function output_widget($region, $place, $themeobject, $template, $request, $qa_content) { if (!qa_opt('event_logger_to_database')) { return; } $badges = qa_db_read_all_assoc(qa_db_query_sub('SELECT event,handle,params, UNIX_TIMESTAMP(datetime) AS datetime FROM ^eventlog WHERE event=$' . (qa_opt('badge_widget_date_max') ? ' AND DATE_SUB(CURDATE(),INTERVAL ' . (int) qa_opt('badge_widget_date_max') . ' DAY) <= datetime' : '') . ' ORDER BY datetime DESC' . (qa_opt('badge_widget_list_max') ? ' LIMIT ' . (int) qa_opt('badge_widget_list_max') : ''), 'badge_awarded')); if (empty($badges)) { return; } $themeobject->output('<h2>' . qa_lang('badges/badge_widget_title') . '</h2>'); foreach ($badges as $badge) { $params = array(); $paramsa = explode("\t", $badge['params']); foreach ($paramsa as $param) { $parama = explode('=', $param); $params[$parama[0]] = $parama[1]; } $slug = $params['badge_slug']; $typea = qa_get_badge_type_by_slug($slug); $types = $typea['slug']; $typed = $typea['name']; $badge_name = qa_lang('badges/' . $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, $name); $string = '<span class="badge-' . $types . '" title="' . $desc . ' (' . $typed . ')">' . qa_html($name) . '<br/>- ' . $badge['handle'] . ' -</span>'; $themeobject->output('<div class="badge-widget-entry" style="padding-top:8px;">', $string, '</div>'); } }
function getAllForumEvents($queryRecentEvents, $eventsToShow, $limit) { /* Question2Answer Plugin: Recent Events Widget Author: http://www.echteinfach.tv/ */ $listAllEvents = ''; $countEvents = 0; $listAllEvents .= '<ul class="ra-events">'; while (($row = qa_db_read_one_assoc($queryRecentEvents, true)) !== null) { if (in_array($row['event'], $eventsToShow)) { // question title $qTitle = ''; // workaround: convert tab jumps to & to be able to use query function $toURL = str_replace("\t", "&", $row['params']); // echo $toURL."<br />"; // we get e.g. parentid=4523&parent=array(65)&postid=4524&answer=array(40) parse_str($toURL, $data); // parse URL to associative array $data // now we can access the following variables in array $data if they exist in toURL $linkToPost = "-"; // find out type, if Q set link directly, if A or C do query to get correct link $postid = isset($data['postid']) ? $data['postid'] : null; if ($postid !== null) { $getPostType = mysql_fetch_array(qa_db_query_sub("SELECT type,parentid FROM `^posts` WHERE `postid` = #", $postid)); $postType = $getPostType[0]; // type, and $getPostType[1] is parentid if ($postType == "A") { $getQtitle = mysql_fetch_array(qa_db_query_sub("SELECT title FROM `^posts` WHERE `postid` = # LIMIT 1", $getPostType[1])); $qTitle = isset($getQtitle[0]) ? $getQtitle[0] : ""; // get correct public URL $activity_url = qa_path_html(qa_q_request($getPostType[1], $qTitle), null, qa_opt('site_url'), null, null); $linkToPost = $activity_url . "?show=" . $postid . "#a" . $postid; } else { if ($postType == "C") { // get question link from answer $getQlink = mysql_fetch_array(qa_db_query_sub("SELECT parentid,type FROM `^posts` WHERE `postid` = # LIMIT 1", $getPostType[1])); $linkToQuestion = $getQlink[0]; if ($getQlink[1] == "A") { $getQtitle = mysql_fetch_array(qa_db_query_sub("SELECT title FROM `^posts` WHERE `postid` = # LIMIT 1", $getQlink[0])); $qTitle = isset($getQtitle[0]) ? $getQtitle[0] : ""; // get correct public URL $activity_url = qa_path_html(qa_q_request($linkToQuestion, $qTitle), null, qa_opt('site_url'), null, null); $linkToPost = $activity_url . "?show=" . $postid . "#c" . $postid; } else { // default: comment on question $getQtitle = mysql_fetch_array(qa_db_query_sub("SELECT title FROM `^posts` WHERE `postid` = # LIMIT 1", $getPostType[1])); $qTitle = isset($getQtitle[0]) ? $getQtitle[0] : ""; // get correct public URL $activity_url = qa_path_html(qa_q_request($getPostType[1], $qTitle), null, qa_opt('site_url'), null, null); $linkToPost = $activity_url . "?show=" . $postid . "#c" . $postid; } } else { if ($postType == "Q_HIDDEN") { $qTitle = ''; } else { // question has correct postid to link // $questionTitle = (isset($data['title'])) ? $data['title'] : ""; $getQtitle = mysql_fetch_array(qa_db_query_sub("SELECT title FROM `^posts` WHERE `postid` = # LIMIT 1", $postid)); $qTitle = isset($getQtitle[0]) ? $getQtitle[0] : ""; // get correct public URL // $activity_url = qa_path_html(qa_q_request($getPostType[1], $qTitle), null, qa_opt('site_url'), null, null); $activity_url = qa_path_html(qa_q_request($postid, $qTitle), null, qa_opt('site_url'), null, null); $linkToPost = $activity_url; } } } } elseif ($row['event'] == 'badge_awarded') { $toURL = str_replace("\t", "&", $row['params']); parse_str($toURL, $data); $badge = qa_get_badge_type_by_slug($data['badge_slug']); $badge_type = $badge['slug']; $badge_name = qa_opt('badge_' . $data['badge_slug'] . '_name'); $var = qa_opt('badge_' . $data['badge_slug'] . '_var'); $qTitle = $badge_name . ' - ' . qa_badge_desc_replace($data['badge_slug'], $var, false); $linkToPost = qa_path_html('user/' . $row['handle']); } $username = is_null($row['handle']) ? _ra_lang('Anonymous') : htmlspecialchars($row['handle']); $usernameLink = is_null($row['handle']) ? _ra_lang('Anonymous') : '<a target="_blank" class="qa-user-link" href="' . qa_opt('site_url') . 'user/' . $row['handle'] . '">' . ra_name($row['handle']) . '</a>'; // set event name and css class $eventName = ''; if ($row['event'] == "q_post") { $eventName = _ra_lang('asked'); } else { if ($row['event'] == "a_post") { $eventName = _ra_lang('answered'); } else { if ($row['event'] == "c_post") { $eventName = _ra_lang('commented'); } else { if ($row['event'] == "a_select") { $eventName = _ra_lang('selected an answer'); } else { if ($row['event'] == "badge_awarded") { $eventName = _ra_lang('earned a badge'); } } } } } // set event icon class if ($row['event'] == "q_post") { $event_icon = 'icon-question question'; } else { if ($row['event'] == "a_post") { $event_icon = 'icon-chat3 ans'; } else { if ($row['event'] == "c_post") { $event_icon = 'icon-chat2 comment'; } else { if ($row['event'] == "a_select") { $event_icon = 'icon-checkmark selected'; } else { if ($row['event'] == "badge_awarded") { $event_icon = 'icon-badge badge-icon ' . @$badge_type; } } } } } $timeCode = implode(' ', qa_when_to_html($row['unix_time'], qa_opt('show_full_date_days'))); $time = '<span class="time">' . $timeCode . '</span>'; // if question title is empty, question got possibly deleted, do not show frontend! if ($qTitle == '') { continue; } $qTitleShort = mb_substr($qTitle, 0, 22, 'utf-8'); // shorten question title to 22 chars $qTitleShort2 = strlen($qTitle) > 50 ? htmlspecialchars(mb_substr($qTitle, 0, 50, 'utf-8')) . '…' : htmlspecialchars($qTitle); // shorten question title $listAllEvents .= '<li class="event-item">'; $listAllEvents .= '<div class="event-icon pull-left ' . $event_icon . '"></div>'; $listAllEvents .= '<div class="event-inner">'; $listAllEvents .= '<div class="avatar pull-left" data-handle="' . @$row['handle'] . '" data-id="' . qa_handle_to_userid($row['handle']) . '">' . ra_get_avatar(@$row['handle'], 40) . '</div>'; $listAllEvents .= '<div class="event-content">'; $listAllEvents .= '<h4>' . $usernameLink . ' ' . $eventName . ' ' . $time . '</h4>'; if ($row['event'] == "badge_awarded") { $listAllEvents .= '<h5 class="event-title">' . $qTitleShort2 . '</h5>'; } else { $listAllEvents .= '<a class="event-title" href="' . $linkToPost . '">' . $qTitleShort2 . '</a>'; } $listAllEvents .= '</div>'; $listAllEvents .= '</div>'; $listAllEvents .= '</li>'; $countEvents++; if ($countEvents >= $limit) { break; } } } $listAllEvents .= '</ul>'; return $listAllEvents; }
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>' : ' ') . '</td></tr></table>'); } if (empty($fields)) { return; } return array('style' => 'wide', 'title' => qa_opt('user_act_list_title'), 'fields' => $fields); }