function cs_top_users($limit = 5, $size)
 {
     $users = qa_db_read_all_assoc(qa_db_query_sub('SELECT * FROM ^users JOIN ^userpoints ON ^users.userid=^userpoints.userid ORDER BY ^userpoints.points DESC LIMIT #', $limit));
     $output = '<ul class="top-users-list clearfix">';
     foreach ($users as $u) {
         if (defined('QA_WORDPRESS_INTEGRATE_PATH')) {
             require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
             $u['handle'] = qa_post_userid_to_handle($u['userid']);
         }
         $output .= '<li class="top-user clearfix">';
         $output .= cs_get_post_avatar($u, $u['userid'], $size, true);
         $output .= '<div class="top-user-data">';
         $output .= '<span class="points">' . $u['points'] . ' ' . qa_lang('cleanstrap/points') . '</span>';
         $output .= '<a href="' . qa_path_html('user/' . $u['handle']) . '" class="name">' . $u['handle'] . '</a>';
         $output .= '<p class="counts"><span>' . qa_lang_sub('cleanstrap/x_questions', $u['qposts']) . '</span> <span>' . qa_lang_sub('cleanstrap/x_answers', $u['aposts']) . '</span><span>' . qa_lang_sub('cleanstrap/x_comments', $u['cposts']) . '</span></p>';
         $output .= '</div>';
         $output .= '</li>';
     }
     $output .= '</ul>';
     return $output;
 }
 function cs_new_users($limit, $size, $widget_opt)
 {
     $output = '<ul class="users-list clearfix">';
     if (defined('QA_FINAL_WORDPRESS_INTEGRATE_PATH')) {
         global $wpdb;
         $users = $wpdb->get_results("SELECT ID from {$wpdb->users} order by ID DESC LIMIT {$limit}");
         require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
         foreach ($users as $u) {
             $handle = qa_post_userid_to_handle($u->ID);
             $output .= '<li class="user">';
             $output .= '<div class="avatar" data-handle="' . $handle . '" data-id="' . qa_handle_to_userid($handle) . '"><img src="' . cs_get_avatar($u['handle'], $size, false) . '" /></div>';
             $output .= '</li>';
         }
     } else {
         if (qa_opt('avatar_allow_upload') && @$widget_opt['cs_nu_with_avatar']) {
             $users = qa_db_read_all_assoc(qa_db_query_sub("SELECT * FROM ^users WHERE avatarblobid IS NOT NULL ORDER BY created DESC LIMIT #", $limit));
         } elseif (qa_opt('avatar_allow_gravatar') || qa_opt('avatar_default_show') && strlen(qa_opt('avatar_default_blobid'))) {
             $users = qa_db_read_all_assoc(qa_db_query_sub("SELECT * FROM ^users ORDER BY created DESC LIMIT #", $limit));
         }
         //refresh every 10 minutes
         foreach ($users as $u) {
             if (isset($u['handle'])) {
                 $handle = $u['handle'];
                 $avatar = cs_get_avatar($handle, $size, false);
                 if (isset($u['useid'])) {
                     $id = $u['useid'];
                 } else {
                     $id = qa_handle_to_userid($handle);
                 }
                 $output .= '<li class="user">';
                 if (!empty($avatar)) {
                     $output .= '<a href="' . qa_path_html('user/' . $handle) . '"><div class="avatar" data-handle="' . $handle . '" data-id="' . $id . '"><img src="' . $avatar . '" /></div></a>';
                 }
                 $output .= '</li>';
             }
         }
     }
     $output .= '</ul>';
     echo $output;
 }
Exemple #3
0
<?php

/* don't allow this page to be requested directly from browser */
if (!defined('QA_VERSION')) {
    header('Location: /');
    exit;
}
if (!isset($args['raw']['handle'])) {
    require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
    $handle = qa_post_userid_to_handle($args['raw']['userid']);
} else {
    $handle = $args['raw']['handle'];
}
/* Default list layout */
?>
<div class="list-q-layout list-item clearfix <?php 
echo rtrim(' ' . @$args['classes']);
?>
" <?php 
echo @$args['tags'];
?>
>
	<?php 
if (isset($args['raw']['userfavoriteq']) && $args['raw']['userfavoriteq'] == 1) {
    echo '<i class="fav-indicator icon-star"></i>';
}
?>
	<div class="for-left">
		<div class="list-avatar avatar pull-left" data-handle="<?php 
echo $handle;
?>
Exemple #4
0
function qa_post_set_hidden($postid, $hidden = true, $byuserid = null)
{
    $oldpost = qa_post_get_full($postid, 'QAC');
    $byhandle = qa_post_userid_to_handle($byuserid);
    switch ($oldpost['basetype']) {
        case 'Q':
            $answers = qa_post_get_question_answers($postid);
            $commentsfollows = qa_post_get_question_commentsfollows($postid);
            $closepost = qa_post_get_question_closepost($postid);
            qa_question_set_hidden($oldpost, $hidden, $byuserid, $byhandle, null, $answers, $commentsfollows, $closepost);
            break;
        case 'A':
            $question = qa_post_get_full($oldpost['parentid'], 'Q');
            $commentsfollows = qa_post_get_answer_commentsfollows($postid);
            qa_answer_set_hidden($oldpost, $hidden, $byuserid, $byhandle, null, $question, $commentsfollows);
            break;
        case 'C':
            $parent = qa_post_get_full($oldpost['parentid'], 'QA');
            $question = qa_post_parent_to_question($parent);
            qa_comment_set_hidden($oldpost, $hidden, $byuserid, $byhandle, null, $question, $parent);
            break;
    }
}
Exemple #5
0
    function sc_ra_user_answers($limit = 10)
    {
        if (qw_hook_exist(__FUNCTION__)) {
            $args = func_get_args();
            array_unshift($args, $this);
            return qw_event_hook(__FUNCTION__, $args, NULL);
        }
        if (defined('QA_WORDPRESS_INTEGRATE_PATH')) {
            require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
            $handle = qa_post_userid_to_handle($this->content['raw']['userid']);
        } else {
            $handle = $this->content['raw']['account']['handle'];
        }
        ?>
				<div class="widget w-question-list">
					<h3 class="widget-title"><?php 
        ra_lang('My Answers');
        ?>
</h3>
					<?php 
        ra_user_post_list($handle, 'A', $limit);
        ?>
				</div>
			<?php 
    }
Exemple #6
0
function ra_user_post_list($handle, $type, $limit)
{
    $userid = qa_handle_to_userid($handle);
    require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
    $post = qa_db_query_sub('SELECT * FROM ^posts WHERE ^posts.type=$ and ^posts.userid=# ORDER BY ^posts.created DESC LIMIT #', $type, $userid, $limit);
    $output = '<ul class="question-list users-widget">';
    while ($p = mysql_fetch_array($post)) {
        if ($type == 'Q') {
            $what = _ra_lang('asked');
        } elseif ($type == 'A') {
            $what = _ra_lang('answered');
        } elseif ('C') {
            $what = _ra_lang('commented');
        }
        $handle = qa_post_userid_to_handle($p['userid']);
        $output .= '<li id="q-list-' . $p['postid'] . '" class="question-item">';
        if ($type == 'Q') {
            $output .= '<div class="big-ans-count pull-left">' . $p['acount'] . '<span>' . _ra_lang('Ans') . '</span></div>';
        } elseif ($type == 'A') {
            $output .= '<div class="big-ans-count pull-left vote">' . $p['netvotes'] . '<span>' . _ra_lang('Vote') . '</span></div>';
        }
        $output .= '<div class="list-right">';
        if ($type == 'Q') {
            $output .= '<h5><a href="' . qa_q_path_html($p['postid'], $p['title']) . '" title="' . $p['title'] . '">' . qa_html($p['title']) . '</a></h5>';
        } elseif ($type == 'A') {
            $output .= '<h5><a href="' . ra_post_link($p['parentid']) . '#a' . $p['postid'] . '">' . substr(strip_tags($p['content']), 0, 50) . '</a></h5>';
        } else {
            $output .= '<h5><a href="' . ra_post_link($p['parentid']) . '#c' . $p['postid'] . '">' . substr(strip_tags($p['content']), 0, 50) . '</a></h5>';
        }
        $output .= '<div class="list-date"><span class="icon-calendar-2">' . date('d M Y', strtotime($p['created'])) . '</span>';
        $output .= '<span class="icon-chevron-up">' . $p['netvotes'] . ' ' . _ra_lang('votes') . '</span></div>';
        $output .= '</div>';
        $output .= '</li>';
    }
    $output .= '</ul>';
    echo $output;
}
    function cs_relative_post_list($limit, $slug, $type, $return = false, $avatar_size)
    {
        require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
        if (!empty($slug)) {
            if ($type == 'Category') {
                $post_type = 'Q';
                $categories = explode("/", $slug);
                if (count($categories)) {
                    $category_bread_crup = implode(" > ", $categories);
                    $category_link = implode("/", $categories);
                    $categories = array_reverse($categories);
                    $slug = implode("/", $categories);
                }
                $posts = qa_db_read_all_assoc(qa_db_query_sub('SELECT * FROM ^posts WHERE ^posts.type=$
							AND categoryid=(SELECT categoryid FROM ^categories WHERE ^categories.backpath=$ LIMIT 1) 
							ORDER BY ^posts.created DESC LIMIT #', 'Q', $slug, $limit));
                //refresh every 15 minutes
                $title = 'Questions in <a href="' . qa_path_html('questions/' . qa_strtolower($category_link)) . '">' . $category_bread_crup . '</a>';
            } elseif ($type == 'Tags') {
                $post_type = 'Q';
                $title = 'Questions in <a href="' . qa_path_html('tag/' . qa_strtolower($slug)) . '">' . $slug . '</a>';
                $posts = qa_db_read_all_assoc(qa_db_query_sub('SELECT * FROM ^posts WHERE ^posts.type=$
						AND ^posts.postid IN (SELECT postid FROM ^posttags WHERE 
							wordid=(SELECT wordid FROM ^words WHERE word=$ OR word=$ COLLATE utf8_bin LIMIT 1) ORDER BY postcreated DESC)
						ORDER BY ^posts.created DESC LIMIT #', 'Q', $slug, qa_strtolower($slug), $limit));
            } else {
                // Relative to Keyword
                require_once QA_INCLUDE_DIR . 'qa-app-search.php';
                $keyword = $slug;
                $userid = qa_get_logged_in_userid();
                $title = 'Posts About <a href="' . qa_path_html('search/' . qa_strtolower($keyword)) . '">' . $keyword . '</a>';
                //$post=qa_get_search_results($keyword, 0, $limit, $userid , false, false);
                $words = qa_string_to_words($keyword);
                $posts = qa_db_select_with_pending(qa_db_search_posts_selectspec($userid, $words, $words, $words, $words, trim($keyword), 0, false, $limit));
                $output = '<h3 class="widget-title">' . $title . '</h3>';
                $output .= '<ul class="question-list">';
                foreach ($posts as $post) {
                    $post_type = $post['type'];
                    if ($post_type == 'Q') {
                        $what = qa_lang('cleanstrap/asked');
                    } elseif ($post_type == 'A') {
                        $what = qa_lang('cleanstrap/answered');
                    } elseif ('C') {
                        $what = qa_lang('cleanstrap/commented');
                    }
                    $handle = qa_post_userid_to_handle($post['userid']);
                    $avatar = cs_get_post_avatar($post, $avatar_size);
                    $output .= '<li id="q-list-' . $post['postid'] . '" class="question-item">';
                    $output .= '<div class="pull-left avatar" data-handle="' . $handle . '" data-id="' . $post['userid'] . '">' . $avatar . '</div>';
                    $output .= '<div class="list-right">';
                    if ($post_type == 'Q') {
                        $output .= '<a class="title" href="' . qa_q_path_html($post['postid'], $post['title']) . '" title="' . $post['title'] . '">' . cs_truncate(strip_tags($post['title']), 70) . '</a>';
                    } elseif ($post_type == 'A') {
                        $output .= '<p><a href="' . cs_post_link($post['parentid']) . '#a' . $post['postid'] . '">' . cs_truncate(strip_tags($post['content']), 70) . '</a></p>';
                    } else {
                        $output .= '<p><a href="' . cs_post_link($post['parentid']) . '#c' . $post['postid'] . '">' . cs_truncate(strip_tags($post['content']), 70) . '</a></p>';
                    }
                    $output .= '<div class="meta"><a href="' . qa_path_html('user/' . $handle) . '">' . cs_name($handle) . '</a> ' . $what;
                    if ($post_type == 'Q') {
                        $output .= ' <span class="vote-count">' . $post['netvotes'] . ' votes</span>';
                        $output .= ' <span class="ans-count">' . $post['acount'] . ' ans</span>';
                    } elseif ($post_type == 'A') {
                        $output .= ' <span class="vote-count">' . $post['netvotes'] . ' votes</span>';
                    }
                    $output .= '</div></div>';
                    $output .= '</li>';
                }
                $output .= '</ul>';
                if ($return) {
                    return $output;
                }
                echo $output;
                return;
            }
        } else {
            return;
        }
        $output = '<h3 class="widget-title">' . $title . '</h3>';
        $output .= '<ul class="question-list">';
        foreach ($posts as $p) {
            if (empty($p['userid'])) {
                $p['userid'] = NULL;
            }
            // to prevent error for anonymous posts while calling qa_post_userid_to_handle()
            if ($post_type == 'Q') {
                $what = qa_lang_html('cleanstrap/asked');
            } elseif ($post_type == 'A') {
                $what = qa_lang_html('cleanstrap/answered');
            } elseif ('C') {
                $what = qa_lang_html('cleanstrap/commented');
            }
            $handle = qa_post_userid_to_handle($p['userid']);
            $avatar = cs_get_avatar($handle, 35, false);
            $output .= '<li id="q-list-' . $p['postid'] . '" class="question-item">';
            $output .= '<div class="pull-left avatar" data-handle="' . $handle . '" data-id="' . qa_handle_to_userid($handle) . '">' . (isset($avatar) ? '<img src="' . $avatar . '" />' : '') . '</div>';
            $output .= '<div class="list-right">';
            if ($post_type == 'Q') {
                $output .= '<a class="title" href="' . qa_q_path_html($p['postid'], $p['title']) . '" title="' . $p['title'] . '">' . cs_truncate(qa_html($p['title']), 70) . '</a>';
            } elseif ($post_type == 'A') {
                $output .= '<p><a href="' . cs_post_link($p['parentid']) . '#a' . $p['postid'] . '">' . cs_truncate(strip_tags($p['content']), 70) . '</a></p>';
            } else {
                $output .= '<p><a href="' . cs_post_link($p['parentid']) . '#c' . $p['postid'] . '">' . cs_truncate(strip_tags($p['content']), 70) . '</a></p>';
            }
            $output .= '<div class="meta"><a href="' . qa_path_html('user/' . $handle) . '">' . cs_name($handle) . '</a> ' . $what;
            if ($post_type == 'Q') {
                $output .= ' <span class="vote-count">' . $p['netvotes'] . ' votes</span>';
                $output .= ' <span class="ans-count">' . $p['acount'] . ' ans</span>';
            } elseif ($post_type == 'A') {
                $output .= ' <span class="vote-count">' . $p['netvotes'] . ' votes</span>';
            }
            $output .= '</div></div>';
            $output .= '</li>';
        }
        $output .= '</ul>';
        if ($return) {
            return $output;
        }
        echo $output;
    }
    function process_event($event, $userid, $handle, $cookieid, $params)
    {
        if (!qa_opt('event_logger_to_database')) {
            return;
        }
        // needed for function qa_post_userid_to_handle()
        require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
        $twoway = array('a_select', 'q_vote_up', 'a_vote_up', 'q_vote_down', 'a_vote_down');
        $special = array('a_post', 'c_post');
        if (in_array($event, $twoway)) {
            if (strpos($event, 'u_') === 0) {
                $uid = $params['userid'];
            } else {
                $uid = qa_db_read_one_value(qa_db_query_sub('SELECT userid FROM ^posts WHERE postid=#', $params['postid']), true);
            }
            if ($uid != $userid) {
                $ohandle = qa_post_userid_to_handle($uid);
                $oevent = 'in_' . $event;
                $paramstring = '';
                foreach ($params as $key => $value) {
                    $paramstring .= (strlen($paramstring) ? "\t" : '') . $key . '=' . $this->value_to_text($value);
                }
                // write in_ events to qa_eventlog
                qa_db_query_sub('INSERT INTO ^eventlog (datetime, ipaddress, userid, handle, cookieid, event, params) ' . 'VALUES (NOW(), $, $, $, #, $, $)', qa_remote_ip_address(), $uid, $ohandle, $cookieid, $oevent, $paramstring);
            }
        }
        // comments and answers
        if (in_array($event, $special)) {
            // userid (recent C)
            $uid = qa_db_read_one_value(qa_db_query_sub('SELECT userid FROM ^posts WHERE postid=#', $params['postid']), true);
            // userid (QA)
            $pid = qa_db_read_one_value(qa_db_query_sub('SELECT userid FROM ^posts WHERE postid=#', $params['parentid']), true);
            // if QA poster is not the same as commenter
            if ($pid != $userid) {
                $ohandle = qa_post_userid_to_handle($pid);
                switch ($event) {
                    case 'a_post':
                        $oevent = 'in_a_question';
                        break;
                    case 'c_post':
                        if ($params['parenttype'] == 'Q') {
                            $oevent = 'in_c_question';
                        } else {
                            $oevent = 'in_c_answer';
                        }
                        break;
                }
                $paramstring = '';
                foreach ($params as $key => $value) {
                    $paramstring .= (strlen($paramstring) ? "\t" : '') . $key . '=' . $this->value_to_text($value);
                }
                qa_db_query_sub('INSERT INTO ^eventlog (datetime, ipaddress, userid, handle, cookieid, event, params) ' . 'VALUES (NOW(), $, $, $, #, $, $)', qa_remote_ip_address(), $pid, $ohandle, $cookieid, $oevent, $paramstring);
            }
            // q2apro: added logging for comments in thread
            if ($event == 'c_post') {
                $oevent = 'in_c_comment';
                // check if we have more comments to the parent
                // DISTINCT: if a user has more than 1 comment just select him unique to inform him only once
                $precCommentsQuery = qa_db_query_sub('SELECT DISTINCT userid FROM `^posts`
												WHERE `parentid` = #
												AND `type` = "C"
												AND `userid` IS NOT NULL
												', $params['parentid']);
                while (($comment = qa_db_read_one_assoc($precCommentsQuery, true)) !== null) {
                    $userid_CommThr = $comment['userid'];
                    // unique
                    // don't inform user that comments, and don't inform user that comments on his own question/answer
                    if ($userid_CommThr != $uid && $userid_CommThr != $pid) {
                        $ohandle = qa_post_userid_to_handle($userid_CommThr);
                        $paramstring = '';
                        foreach ($params as $key => $value) {
                            $paramstring .= (strlen($paramstring) ? "\t" : '') . $key . '=' . $this->value_to_text($value);
                        }
                        qa_db_query_sub('INSERT INTO ^eventlog (datetime, ipaddress, userid, handle, cookieid, event, params) ' . 'VALUES (NOW(), $, $, $, #, $, $)', qa_remote_ip_address(), $userid_CommThr, $ohandle, $cookieid, $oevent, $paramstring);
                    }
                }
            }
            // end in_c_comment
        }
        // end in_array
    }
    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;
    }