public function process_request($request) { if ($request == 'facebook-login') { $app_id = qa_opt('facebook_app_id'); $app_secret = qa_opt('facebook_app_secret'); $tourl = qa_get('to'); if (!strlen($tourl)) { $tourl = qa_path_absolute(''); } if (strlen($app_id) && strlen($app_secret)) { require_once $this->directory . 'facebook.php'; $facebook = new Facebook(array('appId' => $app_id, 'secret' => $app_secret, 'cookie' => true)); $fb_userid = $facebook->getUser(); if ($fb_userid) { try { $user = $facebook->api('/me?fields=email,name,verified,location,website,about,picture.width(250)'); if (is_array($user)) { qa_log_in_external_user('facebook', $fb_userid, array('email' => @$user['email'], 'handle' => @$user['name'], 'confirmed' => @$user['verified'], 'name' => @$user['name'], 'location' => @$user['location']['name'], 'website' => @$user['website'], 'about' => @$user['bio'], 'avatar' => strlen(@$user['picture']['data']['url']) ? qa_retrieve_url($user['picture']['data']['url']) : null)); } } catch (FacebookApiException $e) { } } else { qa_redirect_raw($facebook->getLoginUrl(array('redirect_uri' => $tourl))); } } qa_redirect_raw($tourl); } }
public function login_html($tourl, $context) { $app_id = qa_opt('facebook_app_id'); if (!strlen($app_id)) { return; } $this->facebook_html(qa_path_absolute('facebook-login', array('to' => $tourl)), false, $context); }
function qa_start_reset_user($userid) { require_once QA_INCLUDE_DIR . 'qa-db-users.php'; require_once QA_INCLUDE_DIR . 'qa-app-options.php'; require_once QA_INCLUDE_DIR . 'qa-app-emails.php'; require_once QA_INCLUDE_DIR . 'qa-db-selects.php'; qa_db_user_set($userid, 'emailcode', qa_db_user_rand_emailcode()); $userinfo = qa_db_select_with_pending(qa_db_user_account_selectspec($userid, true)); if (!qw_send_notification($userid, $userinfo['email'], $userinfo['handle'], qa_lang('emails/reset_subject'), nl2br(qa_lang('emails/reset_body')), array('^code' => $userinfo['emailcode'], '^url' => qa_path_absolute('reset', array('c' => $userinfo['emailcode'], 'e' => $userinfo['email']))))) { qa_fatal_error('Could not send reset password email'); } }
function process_request($request) { @ini_set('display_errors', 0); // we don't want to show PHP errors inside XML $titlexml = qa_xml(qa_opt('site_title')); $template = str_replace('_searchTerms_placeholder_', '{searchTerms}', qa_path_absolute('search', array('q' => '_searchTerms_placeholder_'))); header('Content-type: text/xml; charset=utf-8'); echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; echo '<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">' . "\n"; echo "\t<ShortName>" . $titlexml . "</ShortName>\n"; echo "\t<Description>" . qa_xml(qa_lang('main/search_button')) . ' ' . $titlexml . "</Description>\n"; echo "\t" . '<Url type="text/html" method="get" template="' . qa_xml($template) . '"/>' . "\n"; echo "\t<InputEncoding>UTF-8</InputEncoding>\n"; echo '</OpenSearchDescription>' . "\n"; return null; }
function send_default_emails($event, $userid, $handle, $cookieid, $params) { switch ($event) { case 'q_queue': case 'q_requeue': if (qa_opt('moderate_notify_admin')) { qw_send_notification(null, qa_opt('feedback_email'), null, $event == 'q_requeue' ? qa_lang('emails/remoderate_subject') : qa_lang('emails/moderate_subject'), $event == 'q_requeue' ? nl2br(qa_lang('emails/remoderate_body')) : nl2br(qa_lang('emails/moderate_body')), array('^p_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : (strlen(@$oldquestion['name']) ? $oldquestion['name'] : qa_lang('main/anonymous'))), '^p_context' => trim(@$params['title'] . "\n\n" . $params['text']), '^url' => qa_q_path($params['postid'], $params['title'], true), '^a_url' => qa_path_absolute('admin/moderate'))); } break; case 'a_queue': case 'a_requeue': if (qa_opt('moderate_notify_admin')) { qw_send_notification(null, qa_opt('feedback_email'), null, $event == 'a_requeue' ? qa_lang('emails/remoderate_subject') : qa_lang('emails/moderate_subject'), $event == 'a_requeue' ? nl2br(qa_lang('emails/remoderate_body')) : nl2br(qa_lang('emails/moderate_body')), array('^p_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : (strlen(@$oldanswer['name']) ? $oldanswer['name'] : qa_lang('main/anonymous'))), '^p_context' => $params['text'], '^url' => qa_q_path($params['parentid'], $params['parent']['title'], true, 'A', $params['postid']), '^a_url' => qa_path_absolute('admin/moderate'))); } break; case 'c_queue': case 'c_requeue': if (qa_opt('moderate_notify_admin')) { qw_send_notification(null, qa_opt('feedback_email'), null, $event == 'c_requeue' ? qa_lang('emails/remoderate_subject') : qa_lang('emails/moderate_subject'), $event == 'c_requeue' ? nl2br(qa_lang('emails/remoderate_body')) : nl2br(qa_lang('emails/moderate_body')), array('^p_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : (strlen(@$oldcomment['name']) ? $oldcomment['name'] : (strlen(@$oldanswer['name']) ? $oldanswer['name'] : qa_lang('main/anonymous')))), '^p_context' => $params['text'], '^url' => qa_q_path($params['questionid'], $params['question']['title'], true, 'C', $params['postid']), '^a_url' => qa_path_absolute('admin/moderate'))); } break; case 'q_flag': case 'a_flag': case 'c_flag': $flagcount = $params['flagcount']; $oldpost = $params['oldpost']; $notifycount = $flagcount - qa_opt('flagging_notify_first'); if ($notifycount >= 0 && $notifycount % qa_opt('flagging_notify_every') == 0) { qw_send_notification(null, qa_opt('feedback_email'), null, qa_lang('emails/flagged_subject'), nl2br(qa_lang('emails/flagged_body')), array('^p_handle' => isset($oldpost['handle']) ? $oldpost['handle'] : (strlen($oldpost['name']) ? $oldpost['name'] : 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(@$oldpost['title'] . "\n\n" . qa_viewer_text($oldpost['content'], $oldpost['format'])), '^url' => qa_q_path($params['questionid'], $params['question']['title'], true, $oldpost['basetype'], $oldpost['postid']), '^a_url' => qa_path_absolute('admin/flagged'))); } break; case 'u_register': if (qa_opt('register_notify_admin')) { qw_send_notification(null, qa_opt('feedback_email'), null, qa_lang('emails/u_registered_subject'), qa_opt('moderate_users') ? nl2br(qa_lang('emails/u_to_approve_body')) : nl2br(qa_lang('emails/u_registered_body')), array('^u_handle' => $handle, '^url' => qa_path_absolute('user/' . $handle), '^a_url' => qa_path_absolute('admin/approve'))); } break; } }
function process_request($request) { if ($request == 'facebook-login') { $app_id = qa_opt('facebook_app_id'); $app_secret = qa_opt('facebook_app_secret'); $tourl = qa_get('to'); if (!strlen($tourl)) { $tourl = qa_path_absolute(''); } if (strlen($app_id) && strlen($app_secret)) { if (!function_exists('json_decode')) { // work around fact that PHP might not have JSON extension installed require_once $this->directory . 'JSON.php'; function json_decode($json) { $decoder = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); return $decoder->decode($json); } } require_once $this->directory . 'facebook.php'; $facebook = new Facebook(array('appId' => $app_id, 'secret' => $app_secret, 'cookie' => true)); $fb_userid = $facebook->getUser(); if ($fb_userid) { try { $user = $facebook->api('/me?fields=email,name,verified,location,website,about,picture'); if (is_array($user)) { qa_log_in_external_user('facebook', $fb_userid, array('email' => @$user['email'], 'handle' => @$user['name'], 'confirmed' => @$user['verified'], 'name' => @$user['name'], 'location' => @$user['location']['name'], 'website' => @$user['website'], 'about' => @$user['bio'], 'avatar' => strlen(@$user['picture']['data']['url']) ? qa_retrieve_url($user['picture']['data']['url']) : null)); } } catch (FacebookApiException $e) { } } else { qa_redirect_raw($facebook->getLoginUrl(array('redirect_uri' => $tourl))); } } qa_redirect_raw($tourl); } }
function qa_mailing_send_one($userid, $handle, $email, $emailcode) { require_once QA_INCLUDE_DIR . 'qa-app-emails.php'; require_once QA_INCLUDE_DIR . 'qa-db-users.php'; if (!strlen(trim($emailcode))) { $emailcode = qa_db_user_rand_emailcode(); qa_db_user_set($userid, 'emailcode', $emailcode); } $unsubscribeurl = qa_path_absolute('unsubscribe', array('c' => $emailcode, 'u' => $handle)); return qa_send_email(array('fromemail' => qa_opt('mailing_from_email'), 'fromname' => qa_opt('mailing_from_name'), 'toemail' => $email, 'toname' => $handle, 'subject' => qa_opt('mailing_subject'), 'body' => trim(qa_opt('mailing_body')) . "\n\n\n" . qa_lang('users/unsubscribe') . ' ' . $unsubscribeurl, 'html' => false)); }
} else { if (empty($inmessage)) { $errors['message'] = qa_lang('misc/message_empty'); } if (empty($errors)) { require_once QA_INCLUDE_DIR . 'qa-db-messages.php'; require_once QA_INCLUDE_DIR . 'qa-app-emails.php'; if (qa_opt('show_message_history')) { $messageid = qa_db_message_create($loginuserid, $toaccount['userid'], $inmessage, '', false); } else { $messageid = null; } $fromhandle = qa_get_logged_in_handle(); $canreply = !(qa_get_logged_in_flags() & QA_USER_FLAGS_NO_MESSAGES); $more = strtr(qa_lang($canreply ? 'emails/private_message_reply' : 'emails/private_message_info'), array('^f_handle' => $fromhandle, '^url' => qa_path_absolute($canreply ? 'message/' . $fromhandle : 'user/' . $fromhandle))); $subs = array('^message' => $inmessage, '^f_handle' => $fromhandle, '^f_url' => qa_path_absolute('user/' . $fromhandle), '^more' => $more, '^a_url' => qa_path_absolute('account')); if (qa_send_notification($toaccount['userid'], $toaccount['email'], $toaccount['handle'], qa_lang('emails/private_message_subject'), qa_lang('emails/private_message_body'), $subs)) { $messagesent = true; } else { $pageerror = qa_lang_html('main/general_error'); } qa_report_event('u_message', $loginuserid, qa_get_logged_in_handle(), qa_cookie_get(), array('userid' => $toaccount['userid'], 'handle' => $toaccount['handle'], 'messageid' => $messageid, 'message' => $inmessage)); if ($messagesent && qa_opt('show_message_history')) { // show message as part of general history qa_redirect(qa_request(), array('state' => 'message-sent')); } } } } // Prepare content for theme $qa_content = qa_content_prepare();
function head_metas() { qa_html_theme_base::head_metas(); if (qa_opt('useo_cat_canonical_enable')) { $cat_slugs = useo_get_current_category_slug(); if ($cat_slugs) { // it's a category page $path = qa_path_absolute(implode('/', $cat_slugs)); $this->output('<link rel="canonical" href="' . $path . '">'); } } }
function ra_get_avatar($handle, $size = 40, $html = true) { $userid = qa_handle_to_userid($handle); if (defined('QA_WORDPRESS_INTEGRATE_PATH')) { $img_html = get_avatar(qa_get_user_email($userid), $size); } else { if (QA_FINAL_EXTERNAL_USERS) { $img_html = qa_get_external_avatar_html($userid, $size, false); } else { if (!isset($handle)) { if (qa_opt('avatar_allow_upload') && qa_opt('avatar_default_show') && strlen(qa_opt('avatar_default_blobid'))) { $img = qa_opt('avatar_default_blobid'); } else { $img = ''; } } else { $f = ra_user_data($handle); if (empty($f[0]['avatarblobid'])) { if (qa_opt('avatar_allow_upload') && qa_opt('avatar_default_show') && strlen(qa_opt('avatar_default_blobid'))) { $img = qa_opt('avatar_default_blobid'); } else { $img = ''; } } else { $img = $f[0]['avatarblobid']; } } } } if (empty($img)) { return; } if ($html) { return '<a href="' . qa_path_absolute('user/' . $handle) . '"><img src="' . qa_path_absolute('', array('qa' => 'image', 'qa_blobid' => $img, 'qa_size' => $size)) . '" /></a>'; } elseif (!empty($img)) { return qa_path_absolute('', array('qa' => 'image', 'qa_blobid' => $img, 'qa_size' => $size)); } }
function sc_ra_user_compact() { if (qw_hook_exist(__FUNCTION__)) { $args = func_get_args(); array_unshift($args, $this); return qw_event_hook(__FUNCTION__, $args, NULL); } $handle = explode('/', qa_request()); $handle = $handle[1]; ob_start(); ?> <div class="user-compact"> <div class="user-info clearfix"> <div class="avatar pull-left"> <?php echo ra_get_avatar($handle, 40); ?> </div> <div class="name-point"> <h5><?php echo $handle; ?> </h5> <span class="points"><?php echo ra_user_points($handle); ?> </span> </div> </div> <ul class="user-list-menu"> <?php if (ra_is_admin()) { echo '<li class="edit-profile-link"><a id="edit-user" class="btn btn-xs btn-success edit-profile icon-edit" href="' . qa_path_absolute('user/' . $handle, array('state' => 'edit')) . '">Edit User</a></li>'; } foreach ($this->content['navigation']['sub'] as $k => $nav) { if ($k != 'wall') { echo '<li><a href="' . @$nav['url'] . '">' . @$nav['label'] . '</a></li>'; } } ?> </ul> </div> <?php $this->output(ob_get_clean()); }
require_once QA_INCLUDE_DIR . 'util/string.php'; $inmessage = qa_post_text('message'); $inname = qa_post_text('name'); $inemail = qa_post_text('email'); $inreferer = qa_post_text('referer'); if (!qa_check_form_security_code('feedback', qa_post_text('code'))) { $pageerror = qa_lang_html('misc/form_security_again'); } else { if (empty($inmessage)) { $errors['message'] = qa_lang('misc/feedback_empty'); } if ($usecaptcha) { qa_captcha_validate_post($errors); } if (empty($errors)) { $subs = array('^message' => $inmessage, '^name' => empty($inname) ? '-' : $inname, '^email' => empty($inemail) ? '-' : $inemail, '^previous' => empty($inreferer) ? '-' : $inreferer, '^url' => isset($userid) ? qa_path_absolute('user/' . qa_get_logged_in_handle()) : '-', '^ip' => qa_remote_ip_address(), '^browser' => @$_SERVER['HTTP_USER_AGENT']); if (qa_send_email(array('fromemail' => qa_email_validate(@$inemail) ? $inemail : qa_opt('from_email'), 'fromname' => $inname, 'toemail' => qa_opt('feedback_email'), 'toname' => qa_opt('site_title'), 'subject' => qa_lang_sub('emails/feedback_subject', qa_opt('site_title')), 'body' => strtr(qa_lang('emails/feedback_body'), $subs), 'html' => false))) { $feedbacksent = true; } else { $pageerror = qa_lang_html('main/general_error'); } qa_report_event('feedback', $userid, qa_get_logged_in_handle(), qa_cookie_get(), array('email' => $inemail, 'name' => $inname, 'message' => $inmessage, 'previous' => $inreferer, 'browser' => @$_SERVER['HTTP_USER_AGENT'])); } } } // Prepare content for theme $qa_content = qa_content_prepare(); $qa_content['title'] = qa_lang_html('misc/feedback_title'); $qa_content['error'] = @$pageerror; $qa_content['form'] = array('tags' => 'method="post" action="' . qa_self_html() . '"', 'style' => 'tall', 'fields' => array('message' => array('type' => $feedbacksent ? 'static' : '', 'label' => qa_lang_html_sub('misc/feedback_message', qa_opt('site_title')), 'tags' => 'name="message" id="message"', 'value' => qa_html(@$inmessage), 'rows' => 8, 'error' => qa_html(@$errors['message'])), 'name' => array('type' => $feedbacksent ? 'static' : '', 'label' => qa_lang_html('misc/feedback_name'), 'tags' => 'name="name"', 'value' => qa_html(isset($inname) ? $inname : @$userprofile['name'])), 'email' => array('type' => $feedbacksent ? 'static' : '', 'label' => qa_lang_html('misc/feedback_email'), 'tags' => 'name="email"', 'value' => qa_html(isset($inemail) ? $inemail : qa_get_logged_in_email()), 'note' => $feedbacksent ? null : qa_opt('email_privacy'))), 'buttons' => array('send' => array('label' => qa_lang_html('main/send_button'))), 'hidden' => array('dofeedback' => '1', 'code' => qa_get_form_security_code('feedback'), 'referer' => qa_html(isset($inreferer) ? $inreferer : @$_SERVER['HTTP_REFERER']))); if ($usecaptcha && !$feedbacksent) {
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)); } }
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_start_reset_user($userid) { if (qa_to_override(__FUNCTION__)) { $args = func_get_args(); return qa_call_override(__FUNCTION__, $args); } require_once QA_INCLUDE_DIR . 'db/users.php'; require_once QA_INCLUDE_DIR . 'app/options.php'; require_once QA_INCLUDE_DIR . 'app/emails.php'; require_once QA_INCLUDE_DIR . 'db/selects.php'; qa_db_user_set($userid, 'emailcode', qa_db_user_rand_emailcode()); $userinfo = qa_db_select_with_pending(qa_db_user_account_selectspec($userid, true)); if (!qa_send_notification($userid, $userinfo['email'], $userinfo['handle'], qa_lang('emails/reset_subject'), qa_lang('emails/reset_body'), array('^code' => $userinfo['emailcode'], '^url' => qa_path_absolute('reset', array('c' => $userinfo['emailcode'], 'e' => $userinfo['email']))))) { qa_fatal_error('Could not send reset password email'); } }
function process_event($event, $userid, $handle, $cookieid, $params) { require_once QA_INCLUDE_DIR . 'qa-app-emails.php'; require_once QA_INCLUDE_DIR . 'qa-app-format.php'; require_once QA_INCLUDE_DIR . 'qa-util-string.php'; switch ($event) { case 'q_post': $followanswer = @$params['followanswer']; $sendhandle = isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : qa_lang('main/anonymous')); if (isset($followanswer['notify']) && !qa_post_is_by_user($followanswer, $userid, $cookieid)) { $blockwordspreg = qa_get_block_words_preg(); $sendtext = qa_viewer_text($followanswer['content'], $followanswer['format'], array('blockwordspreg' => $blockwordspreg)); qa_send_notification($followanswer['userid'], $followanswer['notify'], @$followanswer['handle'], qa_lang('emails/a_followed_subject'), qa_lang('emails/a_followed_body'), array('^q_handle' => $sendhandle, '^q_title' => qa_block_words_replace($params['title'], $blockwordspreg), '^a_content' => $sendtext, '^url' => qa_q_path($params['postid'], $params['title'], true))); } if (qa_opt('notify_admin_q_post')) { qa_send_notification(null, qa_opt('feedback_email'), null, qa_lang('emails/q_posted_subject'), qa_lang('emails/q_posted_body'), array('^q_handle' => $sendhandle, '^q_title' => $params['title'], '^q_content' => $params['text'], '^url' => qa_q_path($params['postid'], $params['title'], true))); } break; case 'a_post': $question = $params['parent']; if (isset($question['notify']) && !qa_post_is_by_user($question, $userid, $cookieid)) { qa_send_notification($question['userid'], $question['notify'], @$question['handle'], qa_lang('emails/q_answered_subject'), qa_lang('emails/q_answered_body'), array('^a_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : qa_lang('main/anonymous')), '^q_title' => $question['title'], '^a_content' => qa_block_words_replace($params['text'], qa_get_block_words_preg()), '^url' => qa_q_path($question['postid'], $question['title'], true, 'A', $params['postid']))); } break; case 'c_post': $parent = $params['parent']; $question = $params['question']; $senttoemail = array(); // to ensure each user or email gets only one notification about an added comment $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 : (strlen($params['name']) ? $params['name'] : qa_lang('main/anonymous')); $sendcontext = qa_block_words_replace($context, $blockwordspreg); $sendtext = qa_block_words_replace($params['text'], $blockwordspreg); $sendurl = qa_q_path($question['postid'], $question['title'], true, 'C', $params['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 ($params['thread'] as $comment) { 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)); } } break; case 'q_queue': case 'q_requeue': if (qa_opt('moderate_notify_admin')) { qa_send_notification(null, qa_opt('feedback_email'), null, $event == 'q_requeue' ? qa_lang('emails/remoderate_subject') : qa_lang('emails/moderate_subject'), $event == 'q_requeue' ? qa_lang('emails/remoderate_body') : qa_lang('emails/moderate_body'), array('^p_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : (strlen(@$oldquestion['name']) ? $oldquestion['name'] : qa_lang('main/anonymous'))), '^p_context' => trim(@$params['title'] . "\n\n" . $params['text']), '^url' => qa_q_path($params['postid'], $params['title'], true), '^a_url' => qa_path_absolute('admin/moderate'))); } break; case 'a_queue': case 'a_requeue': if (qa_opt('moderate_notify_admin')) { qa_send_notification(null, qa_opt('feedback_email'), null, $event == 'a_requeue' ? qa_lang('emails/remoderate_subject') : qa_lang('emails/moderate_subject'), $event == 'a_requeue' ? qa_lang('emails/remoderate_body') : qa_lang('emails/moderate_body'), array('^p_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : (strlen(@$oldanswer['name']) ? $oldanswer['name'] : qa_lang('main/anonymous'))), '^p_context' => $params['text'], '^url' => qa_q_path($params['parentid'], $params['parent']['title'], true, 'A', $params['postid']), '^a_url' => qa_path_absolute('admin/moderate'))); } break; case 'c_queue': case 'c_requeue': if (qa_opt('moderate_notify_admin')) { qa_send_notification(null, qa_opt('feedback_email'), null, $event == 'c_requeue' ? qa_lang('emails/remoderate_subject') : qa_lang('emails/moderate_subject'), $event == 'c_requeue' ? qa_lang('emails/remoderate_body') : qa_lang('emails/moderate_body'), array('^p_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : (strlen(@$oldcomment['name']) ? $oldcomment['name'] : (strlen(@$oldanswer['name']) ? $oldanswer['name'] : qa_lang('main/anonymous')))), '^p_context' => $params['text'], '^url' => qa_q_path($params['questionid'], $params['question']['title'], true, 'C', $params['postid']), '^a_url' => qa_path_absolute('admin/moderate'))); } break; case 'q_flag': case 'a_flag': case 'c_flag': $flagcount = $params['flagcount']; $oldpost = $params['oldpost']; $notifycount = $flagcount - qa_opt('flagging_notify_first'); if ($notifycount >= 0 && $notifycount % qa_opt('flagging_notify_every') == 0) { qa_send_notification(null, qa_opt('feedback_email'), null, qa_lang('emails/flagged_subject'), qa_lang('emails/flagged_body'), array('^p_handle' => isset($oldpost['handle']) ? $oldpost['handle'] : (strlen($oldpost['name']) ? $oldpost['name'] : 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(@$oldpost['title'] . "\n\n" . qa_viewer_text($oldpost['content'], $oldpost['format'])), '^url' => qa_q_path($params['questionid'], $params['question']['title'], true, $oldpost['basetype'], $oldpost['postid']), '^a_url' => qa_path_absolute('admin/flagged'))); } break; case 'a_select': $answer = $params['answer']; if (isset($answer['notify']) && !qa_post_is_by_user($answer, $userid, $cookieid)) { $blockwordspreg = qa_get_block_words_preg(); $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' => qa_block_words_replace($params['parent']['title'], $blockwordspreg), '^a_content' => $sendcontent, '^url' => qa_q_path($params['parentid'], $params['parent']['title'], true, 'A', $params['postid']))); } break; case 'u_register': if (qa_opt('register_notify_admin')) { qa_send_notification(null, qa_opt('feedback_email'), null, qa_lang('emails/u_registered_subject'), qa_opt('moderate_users') ? qa_lang('emails/u_to_approve_body') : qa_lang('emails/u_registered_body'), array('^u_handle' => $handle, '^url' => qa_path_absolute('user/' . $handle), '^a_url' => qa_path_absolute('admin/approve'))); } break; case 'u_level': if ($params['level'] >= QA_USER_LEVEL_APPROVED && $params['oldlevel'] < QA_USER_LEVEL_APPROVED) { qa_send_notification($params['userid'], null, $params['handle'], qa_lang('emails/u_approved_subject'), qa_lang('emails/u_approved_body'), array('^url' => qa_path_absolute('user/' . $params['handle']))); } break; case 'u_wall_post': if ($userid != $params['userid']) { $blockwordspreg = qa_get_block_words_preg(); qa_send_notification($params['userid'], null, $params['handle'], qa_lang('emails/wall_post_subject'), qa_lang('emails/wall_post_body'), array('^f_handle' => isset($handle) ? $handle : qa_lang('main/anonymous'), '^post' => qa_block_words_replace($params['text'], $blockwordspreg), '^url' => qa_path_absolute('user/' . $params['handle'], null, 'wall'))); } break; } }
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; }