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 qw_notify_users_by_email($event, $postid, $userid, $effecteduserid, $params) { if (!!$effecteduserid) { //get the working user data $logged_in_handle = qa_get_logged_in_handle(); $logged_in_user_name = qw_get_name_from_userid($userid); $logged_in_user_name = !!$logged_in_user_name ? $logged_in_user_name : $logged_in_handle; $name = qw_get_name_from_userid($effecteduserid); switch ($event) { case 'a_post': case 'related': $parent = isset($params['parent']) ? $params['parent'] : ""; if (!!$parent) { $name = !!$name ? $name : $parent['handle']; $email = $parent['email']; $handle = $parent['handle']; } else { //seems proper values are not available return; } break; case 'c_post': case 'q_reshow': case 'a_reshow': case 'c_reshow': case 'a_select': case 'q_vote_up': case 'q_vote_down': case 'a_vote_up': case 'a_vote_down': case 'q_favorite': case 'u_favorite': case 'u_message': case 'u_wall_post': case 'u_level': case 'q_post_user_fl': case 'q_post_tag_fl': case 'q_post_cat_fl': //this is because we wont have the $parent['email'] for each effected userids when a these selected events occurs $user_details = qw_get_user_details_from_userid($effecteduserid); $handle = $user_details['handle']; $name = !!$name ? $name : $user_details['handle']; $email = $user_details['email']; break; case 'q_approve': case 'q_reject': $oldquestion = $params['oldquestion']; $handle = $oldquestion['handle']; $name = !!$name ? $name : $oldquestion['handle']; $email = $oldquestion['email']; break; case 'a_approve': case 'a_reject': $oldanswer = $params['oldanswer']; $handle = $oldquestion['handle']; $name = !!$name ? $name : $oldanswer['handle']; $email = $oldanswer['email']; break; case 'c_approve': case 'c_reject': $oldcomment = $params['oldcomment']; $handle = $oldcomment['handle']; $name = !!$name ? $name : $oldcomment['handle']; $email = $oldcomment['email']; break; default: break; } include_once QA_INCLUDE_DIR . 'qa-util-string.php'; $notifying_user['userid'] = $effecteduserid; $notifying_user['name'] = $name; $notifying_user['email'] = $email; $notifying_user['handle'] = isset($handle) ? $handle : qa_lang('main/anonymous'); //consider only first 50 characters for saving notification if ($event === 'u_message') { $content = isset($params['message']) && !empty($params['message']) ? $params['message'] : ""; $title = ""; $canreply = !(qa_get_logged_in_flags() & QA_USER_FLAGS_NO_MESSAGES); $url = qa_path_absolute($canreply ? 'message/' . $logged_in_handle : 'user/' . $logged_in_handle); } else { if ($event === 'u_wall_post') { $content = isset($params['text']) && !empty($params['text']) ? $params['text'] : ""; if (!!$content) { $blockwordspreg = qa_get_block_words_preg(); $content = qa_block_words_replace($content, $blockwordspreg); } $title = ""; $url = qa_path_absolute('user/' . $params['handle'] . '/wall', null, null); } else { if ($event === 'u_level') { $title = ""; $url = qa_path_absolute('user/' . $params['handle']); $old_level = $params['oldlevel']; $new_level = $params['level']; if ($new_level < $old_level) { return; } $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_body_email' : 'notification/u_level_improved_body_email'), array('^done_by' => isset($logged_in_user_name) ? $logged_in_user_name : isset($logged_in_handle) ? $logged_in_handle : qa_lang('main/anonymous'), '^new_designation' => @$new_designation)); } else { if ($event === "q_post_user_fl" || $event === "q_post_tag_fl" || $event === "q_post_cat_fl") { $content = isset($params['text']) && !empty($params['text']) ? $params['text'] : ""; //shrink the email body content if (!!$content && strlen($content) > 50) { $content = qw_shrink_email_body($content, 50); } $title = isset($params['title']) && !empty($params['title']) ? $params['title'] : ""; $url = qa_q_path($params['postid'], $title, true); } else { $content = isset($params['text']) && !empty($params['text']) ? $params['text'] : ""; //shrink the email body content if (!!$content && strlen($content) > 50) { $content = qw_shrink_email_body($content, 50); } $title = isset($params['qtitle']) && !empty($params['qtitle']) ? $params['qtitle'] : ""; $url = qa_q_path($params['qid'], $title, true); } } } } $q_handle = isset($logged_in_user_name) ? $logged_in_user_name : isset($logged_in_handle) ? $logged_in_handle : qa_lang('main/anonymous'); qw_save_email_notification(null, $notifying_user, $logged_in_handle, $event, array('^q_handle' => $q_handle, '^q_title' => $title, '^q_content' => $content, '^url' => !!$url ? $url : "", '^done_by' => $q_handle, '^author_link' => qa_path_absolute('user/' . $q_handle), '^author_pic' => qa_path_absolute('user/' . $q_handle), '^handle' => $handle)); } }