Commit ad9db8be by Scott

Fix line endings

Set to Unix line endings in repo; the gitattributes file means they
will be converted to suit the user’s system.
parent c4967a19
<html> <html>
<head> <head>
<meta http-equiv="refresh" content="2;url=http://www.question2answer.org/versions.php"> <meta http-equiv="refresh" content="2;url=http://www.question2answer.org/versions.php">
</head> </head>
<body> <body>
Redirecting... if nothing happens, <a href="http://www.question2answer.org/versions.php">click here</a>. Redirecting... if nothing happens, <a href="http://www.question2answer.org/versions.php">click here</a>.
</body> </body>
</html> </html>
\ No newline at end of file
<html> <html>
<head> <head>
<meta http-equiv="refresh" content="2;url=http://www.question2answer.org/license.php"> <meta http-equiv="refresh" content="2;url=http://www.question2answer.org/license.php">
</head> </head>
<body> <body>
Redirecting... if nothing happens, <a href="http://www.question2answer.org/license.php">click here</a>. Redirecting... if nothing happens, <a href="http://www.question2answer.org/license.php">click here</a>.
</body> </body>
</html> </html>
\ No newline at end of file
<html> <html>
<head> <head>
<meta http-equiv="refresh" content="2;url=http://www.question2answer.org/install.php"> <meta http-equiv="refresh" content="2;url=http://www.question2answer.org/install.php">
</head> </head>
<body> <body>
Redirecting... if nothing happens, <a href="http://www.question2answer.org/install.php">click here</a>. Redirecting... if nothing happens, <a href="http://www.question2answer.org/install.php">click here</a>.
</body> </body>
</html> </html>
\ No newline at end of file
<?php <?php
/* /*
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: index.php File: index.php
Version: See define()s at top of qa-include/qa-base.php Version: See define()s at top of qa-include/qa-base.php
Description: A stub that only sets up the Q2A root and includes qa-index.php Description: A stub that only sets up the Q2A root and includes qa-index.php
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
// Set base path here so this works with symbolic links for multiple installations // Set base path here so this works with symbolic links for multiple installations
define('QA_BASE_DIR', dirname(empty($_SERVER['SCRIPT_FILENAME']) ? __FILE__ : $_SERVER['SCRIPT_FILENAME']).'/'); define('QA_BASE_DIR', dirname(empty($_SERVER['SCRIPT_FILENAME']) ? __FILE__ : $_SERVER['SCRIPT_FILENAME']).'/');
require 'qa-include/qa-index.php'; require 'qa-include/qa-index.php';
/* /*
Omit PHP closing tag to help avoid accidental output Omit PHP closing tag to help avoid accidental output
*/ */
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
/* /*
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-content/qa-admin.js File: qa-content/qa-admin.js
Version: See define()s at top of qa-include/qa-base.php Version: See define()s at top of qa-include/qa-base.php
Description: Javascript for admin pages to handle Ajax-triggered operations Description: Javascript for admin pages to handle Ajax-triggered operations
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
var qa_recalc_running=0; var qa_recalc_running=0;
window.onbeforeunload=function(event) window.onbeforeunload=function(event)
{ {
if (qa_recalc_running>0) { if (qa_recalc_running>0) {
event=event||window.event; event=event||window.event;
var message=qa_warning_recalc; var message=qa_warning_recalc;
event.returnValue=message; event.returnValue=message;
return message; return message;
} }
}; };
function qa_recalc_click(state, elem, value, noteid) function qa_recalc_click(state, elem, value, noteid)
{ {
if (elem.qa_recalc_running) { if (elem.qa_recalc_running) {
elem.qa_recalc_stopped=true; elem.qa_recalc_stopped=true;
} else { } else {
elem.qa_recalc_running=true; elem.qa_recalc_running=true;
elem.qa_recalc_stopped=false; elem.qa_recalc_stopped=false;
qa_recalc_running++; qa_recalc_running++;
document.getElementById(noteid).innerHTML=''; document.getElementById(noteid).innerHTML='';
elem.qa_original_value=elem.value; elem.qa_original_value=elem.value;
if (value) if (value)
elem.value=value; elem.value=value;
qa_recalc_update(elem, state, noteid); qa_recalc_update(elem, state, noteid);
} }
return false; return false;
} }
function qa_recalc_update(elem, state, noteid) function qa_recalc_update(elem, state, noteid)
{ {
if (state) if (state)
qa_ajax_post('recalc', {state:state, code:(elem.form.elements.code_recalc ? elem.form.elements.code_recalc.value : elem.form.elements.code.value)}, qa_ajax_post('recalc', {state:state, code:(elem.form.elements.code_recalc ? elem.form.elements.code_recalc.value : elem.form.elements.code.value)},
function(lines) { function(lines) {
if (lines[0]=='1') { if (lines[0]=='1') {
if (lines[2]) if (lines[2])
document.getElementById(noteid).innerHTML=lines[2]; document.getElementById(noteid).innerHTML=lines[2];
if (elem.qa_recalc_stopped) if (elem.qa_recalc_stopped)
qa_recalc_cleanup(elem); qa_recalc_cleanup(elem);
else else
qa_recalc_update(elem, lines[1], noteid); qa_recalc_update(elem, lines[1], noteid);
} else if (lines[0]=='0') { } else if (lines[0]=='0') {
document.getElementById(noteid).innerHTML=lines[2]; document.getElementById(noteid).innerHTML=lines[2];
qa_recalc_cleanup(elem); qa_recalc_cleanup(elem);
} else { } else {
qa_ajax_error(); qa_ajax_error();
qa_recalc_cleanup(elem); qa_recalc_cleanup(elem);
} }
} }
); );
else else
qa_recalc_cleanup(elem); qa_recalc_cleanup(elem);
} }
function qa_recalc_cleanup(elem) function qa_recalc_cleanup(elem)
{ {
elem.value=elem.qa_original_value; elem.value=elem.qa_original_value;
elem.qa_recalc_running=null; elem.qa_recalc_running=null;
qa_recalc_running--; qa_recalc_running--;
} }
function qa_mailing_start(noteid, pauseid) function qa_mailing_start(noteid, pauseid)
{ {
qa_ajax_post('mailing', {}, qa_ajax_post('mailing', {},
function (lines) { function (lines) {
if (lines[0]=='1') { if (lines[0]=='1') {
document.getElementById(noteid).innerHTML=lines[1]; document.getElementById(noteid).innerHTML=lines[1];
window.setTimeout(function() { qa_mailing_start(noteid, pauseid); }, 1); // don't recurse window.setTimeout(function() { qa_mailing_start(noteid, pauseid); }, 1); // don't recurse
} else if (lines[0]=='0') { } else if (lines[0]=='0') {
document.getElementById(noteid).innerHTML=lines[1]; document.getElementById(noteid).innerHTML=lines[1];
document.getElementById(pauseid).style.display='none'; document.getElementById(pauseid).style.display='none';
} else { } else {
qa_ajax_error(); qa_ajax_error();
} }
} }
); );
} }
function qa_admin_click(target) function qa_admin_click(target)
{ {
var p=target.name.split('_'); var p=target.name.split('_');
var params={entityid:p[1], action:p[2]}; var params={entityid:p[1], action:p[2]};
params.code=target.form.elements.code.value; params.code=target.form.elements.code.value;
qa_ajax_post('click_admin', params, qa_ajax_post('click_admin', params,
function (lines) { function (lines) {
if (lines[0]=='1') if (lines[0]=='1')
qa_conceal(document.getElementById('p'+p[1]), 'admin'); qa_conceal(document.getElementById('p'+p[1]), 'admin');
else if (lines[0]=='0') { else if (lines[0]=='0') {
alert(lines[1]); alert(lines[1]);
qa_hide_waiting(target); qa_hide_waiting(target);
} else } else
qa_ajax_error(); qa_ajax_error();
} }
); );
qa_show_waiting_after(target, false); qa_show_waiting_after(target, false);
return false; return false;
} }
function qa_version_check(uri, type, version, elem) function qa_version_check(uri, type, version, elem)
{ {
var params={uri:uri, type:type, version:version}; var params={uri:uri, type:type, version:version};
qa_ajax_post('version', params, qa_ajax_post('version', params,
function (lines) { function (lines) {
if (lines[0]=='1') if (lines[0]=='1')
document.getElementById(elem).innerHTML=lines[1]; document.getElementById(elem).innerHTML=lines[1];
} }
); );
} }
/* /*
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-content/qa-page.js File: qa-content/qa-page.js
Version: See define()s at top of qa-include/qa-base.php Version: See define()s at top of qa-include/qa-base.php
Description: Common Javascript including voting, notices and favorites Description: Common Javascript including voting, notices and favorites
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
function qa_reveal(elem, type, callback) function qa_reveal(elem, type, callback)
{ {
if (elem) if (elem)
$(elem).slideDown(400, callback); $(elem).slideDown(400, callback);
} }
function qa_conceal(elem, type, callback) function qa_conceal(elem, type, callback)
{ {
if (elem) if (elem)
$(elem).slideUp(400); $(elem).slideUp(400);
} }
function qa_set_inner_html(elem, type, html) function qa_set_inner_html(elem, type, html)
{ {
if (elem) if (elem)
elem.innerHTML=html; elem.innerHTML=html;
} }
function qa_set_outer_html(elem, type, html) function qa_set_outer_html(elem, type, html)
{ {
if (elem) { if (elem) {
var e=document.createElement('div'); var e=document.createElement('div');
e.innerHTML=html; e.innerHTML=html;
elem.parentNode.replaceChild(e.firstChild, elem); elem.parentNode.replaceChild(e.firstChild, elem);
} }
} }
function qa_show_waiting_after(elem, inside) function qa_show_waiting_after(elem, inside)
{ {
if (elem && !elem.qa_waiting_shown) { if (elem && !elem.qa_waiting_shown) {
var w=document.getElementById('qa-waiting-template'); var w=document.getElementById('qa-waiting-template');
if (w) { if (w) {
var c=w.cloneNode(true); var c=w.cloneNode(true);
c.id=null; c.id=null;
if (inside) if (inside)
elem.insertBefore(c, null); elem.insertBefore(c, null);
else else
elem.parentNode.insertBefore(c, elem.nextSibling); elem.parentNode.insertBefore(c, elem.nextSibling);
elem.qa_waiting_shown=c; elem.qa_waiting_shown=c;
} }
} }
} }
function qa_hide_waiting(elem) function qa_hide_waiting(elem)
{ {
var c=elem.qa_waiting_shown; var c=elem.qa_waiting_shown;
if (c) { if (c) {
c.parentNode.removeChild(c); c.parentNode.removeChild(c);
elem.qa_waiting_shown=null; elem.qa_waiting_shown=null;
} }
} }
function qa_vote_click(elem) function qa_vote_click(elem)
{ {
var ens=elem.name.split('_'); var ens=elem.name.split('_');
var postid=ens[1]; var postid=ens[1];
var vote=parseInt(ens[2]); var vote=parseInt(ens[2]);
var code=elem.form.elements.code.value; var code=elem.form.elements.code.value;
var anchor=ens[3]; var anchor=ens[3];
qa_ajax_post('vote', {postid:postid, vote:vote, code:code}, qa_ajax_post('vote', {postid:postid, vote:vote, code:code},
function(lines) { function(lines) {
if (lines[0]=='1') { if (lines[0]=='1') {
qa_set_inner_html(document.getElementById('voting_'+postid), 'voting', lines.slice(1).join("\n")); qa_set_inner_html(document.getElementById('voting_'+postid), 'voting', lines.slice(1).join("\n"));
} else if (lines[0]=='0') { } else if (lines[0]=='0') {
var mess=document.getElementById('errorbox'); var mess=document.getElementById('errorbox');
if (!mess) { if (!mess) {
var mess=document.createElement('div'); var mess=document.createElement('div');
mess.id='errorbox'; mess.id='errorbox';
mess.className='qa-error'; mess.className='qa-error';
mess.innerHTML=lines[1]; mess.innerHTML=lines[1];
mess.style.display='none'; mess.style.display='none';
} }
var postelem=document.getElementById(anchor); var postelem=document.getElementById(anchor);
var e=postelem.parentNode.insertBefore(mess, postelem); var e=postelem.parentNode.insertBefore(mess, postelem);
qa_reveal(e); qa_reveal(e);
} else } else
qa_ajax_error(); qa_ajax_error();
} }
); );
return false; return false;
} }
function qa_notice_click(elem) function qa_notice_click(elem)
{ {
var ens=elem.name.split('_'); var ens=elem.name.split('_');
var code=elem.form.elements.code.value; var code=elem.form.elements.code.value;
qa_ajax_post('notice', {noticeid:ens[1], code:code}, qa_ajax_post('notice', {noticeid:ens[1], code:code},
function(lines) { function(lines) {
if (lines[0]=='1') if (lines[0]=='1')
qa_conceal(document.getElementById('notice_'+ens[1]), 'notice'); qa_conceal(document.getElementById('notice_'+ens[1]), 'notice');
else if (lines[0]=='0') else if (lines[0]=='0')
alert(lines[1]); alert(lines[1]);
else else
qa_ajax_error(); qa_ajax_error();
} }
); );
return false; return false;
} }
function qa_favorite_click(elem) function qa_favorite_click(elem)
{ {
var ens=elem.name.split('_'); var ens=elem.name.split('_');
var code=elem.form.elements.code.value; var code=elem.form.elements.code.value;
qa_ajax_post('favorite', {entitytype:ens[1], entityid:ens[2], favorite:parseInt(ens[3]), code:code}, qa_ajax_post('favorite', {entitytype:ens[1], entityid:ens[2], favorite:parseInt(ens[3]), code:code},
function (lines) { function (lines) {
if (lines[0]=='1') if (lines[0]=='1')
qa_set_inner_html(document.getElementById('favoriting'), 'favoriting', lines.slice(1).join("\n")); qa_set_inner_html(document.getElementById('favoriting'), 'favoriting', lines.slice(1).join("\n"));
else if (lines[0]=='0') { else if (lines[0]=='0') {
alert(lines[1]); alert(lines[1]);
qa_hide_waiting(elem); qa_hide_waiting(elem);
} else } else
qa_ajax_error(); qa_ajax_error();
} }
); );
qa_show_waiting_after(elem, false); qa_show_waiting_after(elem, false);
return false; return false;
} }
function qa_ajax_post(operation, params, callback) function qa_ajax_post(operation, params, callback)
{ {
jQuery.extend(params, {qa:'ajax', qa_operation:operation, qa_root:qa_root, qa_request:qa_request}); jQuery.extend(params, {qa:'ajax', qa_operation:operation, qa_root:qa_root, qa_request:qa_request});
jQuery.post(qa_root, params, function(response) { jQuery.post(qa_root, params, function(response) {
var header='QA_AJAX_RESPONSE'; var header='QA_AJAX_RESPONSE';
var headerpos=response.indexOf(header); var headerpos=response.indexOf(header);
if (headerpos>=0) if (headerpos>=0)
callback(response.substr(headerpos+header.length).replace(/^\s+/, '').split("\n")); callback(response.substr(headerpos+header.length).replace(/^\s+/, '').split("\n"));
else else
callback([]); callback([]);
}, 'text').error(function(jqXHR) { if (jqXHR.readyState>0) callback([]) }); }, 'text').error(function(jqXHR) { if (jqXHR.readyState>0) callback([]) });
} }
function qa_ajax_error() function qa_ajax_error()
{ {
alert('Unexpected response from server - please try again or switch off Javascript.'); alert('Unexpected response from server - please try again or switch off Javascript.');
} }
\ No newline at end of file
/* /*
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-content/qa-user.js File: qa-content/qa-user.js
Version: See define()s at top of qa-include/qa-base.php Version: See define()s at top of qa-include/qa-base.php
Description: Javascript to handle user page actions Description: Javascript to handle user page actions
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
function qa_submit_wall_post(elem, morelink) function qa_submit_wall_post(elem, morelink)
{ {
var params={}; var params={};
params.message=document.forms.wallpost.message.value; params.message=document.forms.wallpost.message.value;
params.handle=document.forms.wallpost.handle.value; params.handle=document.forms.wallpost.handle.value;
params.start=document.forms.wallpost.start.value; params.start=document.forms.wallpost.start.value;
params.code=document.forms.wallpost.code.value; params.code=document.forms.wallpost.code.value;
params.morelink=morelink ? 1 : 0; params.morelink=morelink ? 1 : 0;
qa_ajax_post('wallpost', params, qa_ajax_post('wallpost', params,
function(lines) { function(lines) {
if (lines[0]=='1') { if (lines[0]=='1') {
var l=document.getElementById('wallmessages'); var l=document.getElementById('wallmessages');
l.innerHTML=lines.slice(2).join("\n"); l.innerHTML=lines.slice(2).join("\n");
var c=document.getElementById(lines[1]); // id of new message var c=document.getElementById(lines[1]); // id of new message
if (c) { if (c) {
c.style.display='none'; c.style.display='none';
qa_reveal(c, 'wallpost'); qa_reveal(c, 'wallpost');
} }
document.forms.wallpost.message.value=''; document.forms.wallpost.message.value='';
qa_hide_waiting(elem); qa_hide_waiting(elem);
} else if (lines[0]=='0') { } else if (lines[0]=='0') {
document.forms.wallpost.qa_click.value=elem.name; document.forms.wallpost.qa_click.value=elem.name;
document.forms.wallpost.submit(); document.forms.wallpost.submit();
} else { } else {
qa_ajax_error(); qa_ajax_error();
} }
} }
); );
qa_show_waiting_after(elem, false); qa_show_waiting_after(elem, false);
return false; return false;
} }
function qa_wall_post_click(messageid, target) function qa_wall_post_click(messageid, target)
{ {
var params={}; var params={};
params.messageid=messageid; params.messageid=messageid;
params.handle=document.forms.wallpost.handle.value; params.handle=document.forms.wallpost.handle.value;
params.start=document.forms.wallpost.start.value; params.start=document.forms.wallpost.start.value;
params.code=document.forms.wallpost.code.value; params.code=document.forms.wallpost.code.value;
params[target.name]=target.value; params[target.name]=target.value;
qa_ajax_post('click_wall', params, qa_ajax_post('click_wall', params,
function (lines) { function (lines) {
if (lines[0]=='1') { if (lines[0]=='1') {
var l=document.getElementById('m'+messageid); var l=document.getElementById('m'+messageid);
var h=lines.slice(1).join("\n"); var h=lines.slice(1).join("\n");
if (h.length) if (h.length)
qa_set_outer_html(l, 'wallpost', h) qa_set_outer_html(l, 'wallpost', h)
else else
qa_conceal(l, 'wallpost'); qa_conceal(l, 'wallpost');
} else { } else {
document.forms.wallpost.qa_click.value=target.name; document.forms.wallpost.qa_click.value=target.name;
document.forms.wallpost.submit(); document.forms.wallpost.submit();
} }
} }
); );
qa_show_waiting_after(target, false); qa_show_waiting_after(target, false);
return false; return false;
} }
function qa_pm_click(messageid, target, box) function qa_pm_click(messageid, target, box)
{ {
var params = {}; var params = {};
params.messageid = messageid; params.messageid = messageid;
params.box = box; params.box = box;
params.handle = document.forms.pmessage.handle.value; params.handle = document.forms.pmessage.handle.value;
params.start = document.forms.pmessage.start.value; params.start = document.forms.pmessage.start.value;
params.code = document.forms.pmessage.code.value; params.code = document.forms.pmessage.code.value;
params[target.name] = target.value; params[target.name] = target.value;
qa_ajax_post('click_pm', params, qa_ajax_post('click_pm', params,
function (lines) { function (lines) {
if (lines[0]=='1') { if (lines[0]=='1') {
var l = document.getElementById('m'+messageid); var l = document.getElementById('m'+messageid);
var h = lines.slice(1).join("\n"); var h = lines.slice(1).join("\n");
if (h.length) if (h.length)
qa_set_outer_html(l, 'pmessage', h) qa_set_outer_html(l, 'pmessage', h)
else else
qa_conceal(l, 'pmessage'); qa_conceal(l, 'pmessage');
} else { } else {
document.forms.pmessage.qa_click.value = target.name; document.forms.pmessage.qa_click.value = target.name;
document.forms.pmessage.submit(); document.forms.pmessage.submit();
} }
} }
); );
qa_show_waiting_after(target, false); qa_show_waiting_after(target, false);
return false; return false;
} }
<?php <?php
/* /*
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-include/qa-ajax-answer.php File: qa-include/qa-ajax-answer.php
Version: See define()s at top of qa-include/qa-base.php Version: See define()s at top of qa-include/qa-base.php
Description: Server-side response to Ajax create answer requests Description: Server-side response to Ajax create answer requests
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
require_once QA_INCLUDE_DIR.'qa-app-users.php'; require_once QA_INCLUDE_DIR.'qa-app-users.php';
require_once QA_INCLUDE_DIR.'qa-app-limits.php'; require_once QA_INCLUDE_DIR.'qa-app-limits.php';
require_once QA_INCLUDE_DIR.'qa-db-selects.php'; require_once QA_INCLUDE_DIR.'qa-db-selects.php';
// Load relevant information about this question // Load relevant information about this question
$questionid=qa_post_text('a_questionid'); $questionid=qa_post_text('a_questionid');
$userid=qa_get_logged_in_userid(); $userid=qa_get_logged_in_userid();
list($question, $childposts)=qa_db_select_with_pending( list($question, $childposts)=qa_db_select_with_pending(
qa_db_full_post_selectspec($userid, $questionid), qa_db_full_post_selectspec($userid, $questionid),
qa_db_full_child_posts_selectspec($userid, $questionid) qa_db_full_child_posts_selectspec($userid, $questionid)
); );
// Check if the question exists, is not closed, and whether the user has permission to do this // Check if the question exists, is not closed, and whether the user has permission to do this
if ((@$question['basetype']=='Q') && (!isset($question['closedbyid'])) && !qa_user_post_permit_error('permit_post_a', $question, QA_LIMIT_ANSWERS)) { if ((@$question['basetype']=='Q') && (!isset($question['closedbyid'])) && !qa_user_post_permit_error('permit_post_a', $question, QA_LIMIT_ANSWERS)) {
require_once QA_INCLUDE_DIR.'qa-app-captcha.php'; require_once QA_INCLUDE_DIR.'qa-app-captcha.php';
require_once QA_INCLUDE_DIR.'qa-app-format.php'; require_once QA_INCLUDE_DIR.'qa-app-format.php';
require_once QA_INCLUDE_DIR.'qa-app-post-create.php'; require_once QA_INCLUDE_DIR.'qa-app-post-create.php';
require_once QA_INCLUDE_DIR.'qa-app-cookies.php'; require_once QA_INCLUDE_DIR.'qa-app-cookies.php';
require_once QA_INCLUDE_DIR.'qa-page-question-view.php'; require_once QA_INCLUDE_DIR.'qa-page-question-view.php';
require_once QA_INCLUDE_DIR.'qa-page-question-submit.php'; require_once QA_INCLUDE_DIR.'qa-page-question-submit.php';
// Try to create the new answer // Try to create the new answer
$usecaptcha=qa_user_use_captcha(qa_user_level_for_post($question)); $usecaptcha=qa_user_use_captcha(qa_user_level_for_post($question));
$answers=qa_page_q_load_as($question, $childposts); $answers=qa_page_q_load_as($question, $childposts);
$answerid=qa_page_q_add_a_submit($question, $answers, $usecaptcha, $in, $errors); $answerid=qa_page_q_add_a_submit($question, $answers, $usecaptcha, $in, $errors);
// If successful, page content will be updated via Ajax // If successful, page content will be updated via Ajax
if (isset($answerid)) { if (isset($answerid)) {
$answer=qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $answerid)); $answer=qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $answerid));
$question=$question+qa_page_q_post_rules($question, null, null, $childposts); // array union $question=$question+qa_page_q_post_rules($question, null, null, $childposts); // array union
$answer=$answer+qa_page_q_post_rules($answer, $question, $answers, null); $answer=$answer+qa_page_q_post_rules($answer, $question, $answers, null);
$usershtml=qa_userids_handles_html(array($answer), true); $usershtml=qa_userids_handles_html(array($answer), true);
$a_view=qa_page_q_answer_view($question, $answer, false, $usershtml, false); $a_view=qa_page_q_answer_view($question, $answer, false, $usershtml, false);
$themeclass=qa_load_theme_class(qa_get_site_theme(), 'ajax-answer', null, null); $themeclass=qa_load_theme_class(qa_get_site_theme(), 'ajax-answer', null, null);
echo "QA_AJAX_RESPONSE\n1\n"; echo "QA_AJAX_RESPONSE\n1\n";
// Send back whether the 'answer' button should still be visible // Send back whether the 'answer' button should still be visible
echo (int)qa_opt('allow_multi_answers')."\n"; echo (int)qa_opt('allow_multi_answers')."\n";
// Send back the count of answers // Send back the count of answers
$countanswers=$question['acount']+1; $countanswers=$question['acount']+1;
if ($countanswers==1) if ($countanswers==1)
echo qa_lang_html('question/1_answer_title')."\n"; echo qa_lang_html('question/1_answer_title')."\n";
else else
echo qa_lang_html_sub('question/x_answers_title', $countanswers)."\n"; echo qa_lang_html_sub('question/x_answers_title', $countanswers)."\n";
// Send back the HTML // Send back the HTML
$themeclass->a_list_item($a_view); $themeclass->a_list_item($a_view);
return; return;
} }
} }
echo "QA_AJAX_RESPONSE\n0\n"; // fall back to non-Ajax submission if there were any problems echo "QA_AJAX_RESPONSE\n0\n"; // fall back to non-Ajax submission if there were any problems
/* /*
Omit PHP closing tag to help avoid accidental output Omit PHP closing tag to help avoid accidental output
*/ */
\ No newline at end of file
<?php <?php
/* /*
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-include/qa-ajax-asktitle.php File: qa-include/qa-ajax-asktitle.php
Version: See define()s at top of qa-include/qa-base.php Version: See define()s at top of qa-include/qa-base.php
Description: Server-side response to Ajax request based on ask a question title Description: Server-side response to Ajax request based on ask a question title
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
require_once QA_INCLUDE_DIR.'qa-db-selects.php'; require_once QA_INCLUDE_DIR.'qa-db-selects.php';
require_once QA_INCLUDE_DIR.'qa-util-string.php'; require_once QA_INCLUDE_DIR.'qa-util-string.php';
require_once QA_INCLUDE_DIR.'qa-app-users.php'; require_once QA_INCLUDE_DIR.'qa-app-users.php';
require_once QA_INCLUDE_DIR.'qa-app-format.php'; require_once QA_INCLUDE_DIR.'qa-app-format.php';
// Collect the information we need from the database // Collect the information we need from the database
$intitle = qa_post_text('title'); $intitle = qa_post_text('title');
$doaskcheck = qa_opt('do_ask_check_qs'); $doaskcheck = qa_opt('do_ask_check_qs');
$doexampletags = qa_using_tags() && qa_opt('do_example_tags'); $doexampletags = qa_using_tags() && qa_opt('do_example_tags');
if ($doaskcheck || $doexampletags) { if ($doaskcheck || $doexampletags) {
$countqs = max($doexampletags ? QA_DB_RETRIEVE_ASK_TAG_QS : 0, $doaskcheck ? qa_opt('page_size_ask_check_qs') : 0); $countqs = max($doexampletags ? QA_DB_RETRIEVE_ASK_TAG_QS : 0, $doaskcheck ? qa_opt('page_size_ask_check_qs') : 0);
$relatedquestions = qa_db_select_with_pending( $relatedquestions = qa_db_select_with_pending(
qa_db_search_posts_selectspec(null, qa_string_to_words($intitle), null, null, null, null, 0, false, $countqs) qa_db_search_posts_selectspec(null, qa_string_to_words($intitle), null, null, null, null, 0, false, $countqs)
); );
} }
// Collect example tags if appropriate // Collect example tags if appropriate
if ($doexampletags) { if ($doexampletags) {
$tagweight = array(); $tagweight = array();
foreach ($relatedquestions as $question) { foreach ($relatedquestions as $question) {
$tags = qa_tagstring_to_tags($question['tags']); $tags = qa_tagstring_to_tags($question['tags']);
foreach ($tags as $tag) foreach ($tags as $tag)
@$tagweight[$tag] += exp($question['score']); @$tagweight[$tag] += exp($question['score']);
} }
arsort($tagweight, SORT_NUMERIC); arsort($tagweight, SORT_NUMERIC);
$exampletags = array(); $exampletags = array();
$minweight = exp(qa_match_to_min_score(qa_opt('match_example_tags'))); $minweight = exp(qa_match_to_min_score(qa_opt('match_example_tags')));
$maxcount = qa_opt('page_size_ask_tags'); $maxcount = qa_opt('page_size_ask_tags');
foreach ($tagweight as $tag => $weight) { foreach ($tagweight as $tag => $weight) {
if ($weight < $minweight) if ($weight < $minweight)
break; break;
$exampletags[] = $tag; $exampletags[] = $tag;
if (count($exampletags) >= $maxcount) if (count($exampletags) >= $maxcount)
break; break;
} }
} }
else else
$exampletags = array(); $exampletags = array();
// Output the response header and example tags // Output the response header and example tags
echo "QA_AJAX_RESPONSE\n1\n"; echo "QA_AJAX_RESPONSE\n1\n";
echo strtr(qa_html(implode(',', $exampletags)), "\r\n", ' ') . "\n"; echo strtr(qa_html(implode(',', $exampletags)), "\r\n", ' ') . "\n";
// Collect and output the list of related questions // Collect and output the list of related questions
if ($doaskcheck) { if ($doaskcheck) {
$minscore = qa_match_to_min_score(qa_opt('match_ask_check_qs')); $minscore = qa_match_to_min_score(qa_opt('match_ask_check_qs'));
$maxcount = qa_opt('page_size_ask_check_qs'); $maxcount = qa_opt('page_size_ask_check_qs');
$relatedquestions = array_slice($relatedquestions, 0, $maxcount); $relatedquestions = array_slice($relatedquestions, 0, $maxcount);
$limitedquestions = array(); $limitedquestions = array();
foreach ($relatedquestions as $question) { foreach ($relatedquestions as $question) {
if ($question['score'] < $minscore) if ($question['score'] < $minscore)
break; break;
$limitedquestions[] = $question; $limitedquestions[] = $question;
} }
$themeclass = qa_load_theme_class(qa_get_site_theme(), 'ajax-asktitle', null, null); $themeclass = qa_load_theme_class(qa_get_site_theme(), 'ajax-asktitle', null, null);
$themeclass->q_ask_similar($limitedquestions, qa_lang_html('question/ask_same_q')); $themeclass->q_ask_similar($limitedquestions, qa_lang_html('question/ask_same_q'));
} }
/* /*
Omit PHP closing tag to help avoid accidental output Omit PHP closing tag to help avoid accidental output
*/ */
\ No newline at end of file
<?php <?php
/* /*
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-include/qa-ajax-category.php File: qa-include/qa-ajax-category.php
Version: See define()s at top of qa-include/qa-base.php Version: See define()s at top of qa-include/qa-base.php
Description: Server-side response to Ajax category information requests Description: Server-side response to Ajax category information requests
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
require_once QA_INCLUDE_DIR.'qa-db-selects.php'; require_once QA_INCLUDE_DIR.'qa-db-selects.php';
$categoryid=qa_post_text('categoryid'); $categoryid=qa_post_text('categoryid');
if (!strlen($categoryid)) if (!strlen($categoryid))
$categoryid=null; $categoryid=null;
list($fullcategory, $categories)=qa_db_select_with_pending( list($fullcategory, $categories)=qa_db_select_with_pending(
qa_db_full_category_selectspec($categoryid, true), qa_db_full_category_selectspec($categoryid, true),
qa_db_category_sub_selectspec($categoryid) qa_db_category_sub_selectspec($categoryid)
); );
echo "QA_AJAX_RESPONSE\n1\n"; echo "QA_AJAX_RESPONSE\n1\n";
echo qa_html(strtr(@$fullcategory['content'], "\r\n", ' ')); // category description echo qa_html(strtr(@$fullcategory['content'], "\r\n", ' ')); // category description
foreach ($categories as $category) foreach ($categories as $category)
echo "\n".$category['categoryid'].'/'.$category['title']; // subcategory information echo "\n".$category['categoryid'].'/'.$category['title']; // subcategory information
/* /*
Omit PHP closing tag to help avoid accidental output Omit PHP closing tag to help avoid accidental output
*/ */
\ No newline at end of file
<?php <?php
/* /*
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-include/qa-ajax-click-admin.php File: qa-include/qa-ajax-click-admin.php
Version: See define()s at top of qa-include/qa-base.php Version: See define()s at top of qa-include/qa-base.php
Description: Server-side response to Ajax single clicks on posts in admin section Description: Server-side response to Ajax single clicks on posts in admin section
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
require_once QA_INCLUDE_DIR.'qa-app-admin.php'; require_once QA_INCLUDE_DIR.'qa-app-admin.php';
require_once QA_INCLUDE_DIR.'qa-app-users.php'; require_once QA_INCLUDE_DIR.'qa-app-users.php';
require_once QA_INCLUDE_DIR.'qa-app-cookies.php'; require_once QA_INCLUDE_DIR.'qa-app-cookies.php';
$entityid=qa_post_text('entityid'); $entityid=qa_post_text('entityid');
$action=qa_post_text('action'); $action=qa_post_text('action');
if (!qa_check_form_security_code('admin/click', qa_post_text('code'))) if (!qa_check_form_security_code('admin/click', qa_post_text('code')))
echo "QA_AJAX_RESPONSE\n0\n".qa_lang('misc/form_security_reload'); echo "QA_AJAX_RESPONSE\n0\n".qa_lang('misc/form_security_reload');
elseif (qa_admin_single_click($entityid, $action)) // permission check happens in here elseif (qa_admin_single_click($entityid, $action)) // permission check happens in here
echo "QA_AJAX_RESPONSE\n1\n"; echo "QA_AJAX_RESPONSE\n1\n";
else else
echo "QA_AJAX_RESPONSE\n0\n".qa_lang('main/general_error'); echo "QA_AJAX_RESPONSE\n0\n".qa_lang('main/general_error');
/* /*
Omit PHP closing tag to help avoid accidental output Omit PHP closing tag to help avoid accidental output
*/ */
\ No newline at end of file
<?php <?php
/* /*
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-include/qa-ajax-click-answer.php File: qa-include/qa-ajax-click-answer.php
Version: See define()s at top of qa-include/qa-base.php Version: See define()s at top of qa-include/qa-base.php
Description: Server-side response to Ajax single clicks on answer Description: Server-side response to Ajax single clicks on answer
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
require_once QA_INCLUDE_DIR.'qa-app-cookies.php'; require_once QA_INCLUDE_DIR.'qa-app-cookies.php';
require_once QA_INCLUDE_DIR.'qa-app-format.php'; require_once QA_INCLUDE_DIR.'qa-app-format.php';
require_once QA_INCLUDE_DIR.'qa-app-users.php'; require_once QA_INCLUDE_DIR.'qa-app-users.php';
require_once QA_INCLUDE_DIR.'qa-db-selects.php'; require_once QA_INCLUDE_DIR.'qa-db-selects.php';
require_once QA_INCLUDE_DIR.'qa-page-question-view.php'; require_once QA_INCLUDE_DIR.'qa-page-question-view.php';
require_once QA_INCLUDE_DIR.'qa-page-question-submit.php'; require_once QA_INCLUDE_DIR.'qa-page-question-submit.php';
// Load relevant information about this answer // Load relevant information about this answer
$answerid=qa_post_text('answerid'); $answerid=qa_post_text('answerid');
$questionid=qa_post_text('questionid'); $questionid=qa_post_text('questionid');
$userid=qa_get_logged_in_userid(); $userid=qa_get_logged_in_userid();
list($answer, $question, $qchildposts, $achildposts)=qa_db_select_with_pending( list($answer, $question, $qchildposts, $achildposts)=qa_db_select_with_pending(
qa_db_full_post_selectspec($userid, $answerid), qa_db_full_post_selectspec($userid, $answerid),
qa_db_full_post_selectspec($userid, $questionid), qa_db_full_post_selectspec($userid, $questionid),
qa_db_full_child_posts_selectspec($userid, $questionid), qa_db_full_child_posts_selectspec($userid, $questionid),
qa_db_full_child_posts_selectspec($userid, $answerid) qa_db_full_child_posts_selectspec($userid, $answerid)
); );
// Check if there was an operation that succeeded // Check if there was an operation that succeeded
if ( if (
(@$answer['basetype']=='A') && (@$answer['basetype']=='A') &&
(@$question['basetype']=='Q') (@$question['basetype']=='Q')
) { ) {
$answers=qa_page_q_load_as($question, $qchildposts); $answers=qa_page_q_load_as($question, $qchildposts);
$question=$question+qa_page_q_post_rules($question, null, null, $qchildposts); // array union $question=$question+qa_page_q_post_rules($question, null, null, $qchildposts); // array union
$answer=$answer+qa_page_q_post_rules($answer, $question, $qchildposts, $achildposts); $answer=$answer+qa_page_q_post_rules($answer, $question, $qchildposts, $achildposts);
if (qa_page_q_single_click_a($answer, $question, $answers, $achildposts, false, $error)) { if (qa_page_q_single_click_a($answer, $question, $answers, $achildposts, false, $error)) {
list($answer, $question)=qa_db_select_with_pending( list($answer, $question)=qa_db_select_with_pending(
qa_db_full_post_selectspec($userid, $answerid), qa_db_full_post_selectspec($userid, $answerid),
qa_db_full_post_selectspec($userid, $questionid) qa_db_full_post_selectspec($userid, $questionid)
); );
// If so, page content to be updated via Ajax // If so, page content to be updated via Ajax
echo "QA_AJAX_RESPONSE\n1\n"; echo "QA_AJAX_RESPONSE\n1\n";
// Send back new count of answers // Send back new count of answers
$countanswers=$question['acount']; $countanswers=$question['acount'];
if ($countanswers==1) if ($countanswers==1)
echo qa_lang_html('question/1_answer_title'); echo qa_lang_html('question/1_answer_title');
else else
echo qa_lang_html_sub('question/x_answers_title', $countanswers); echo qa_lang_html_sub('question/x_answers_title', $countanswers);
// If the answer was not deleted.... // If the answer was not deleted....
if (isset($answer)) { if (isset($answer)) {
$question=$question+qa_page_q_post_rules($question, null, null, $qchildposts); // array union $question=$question+qa_page_q_post_rules($question, null, null, $qchildposts); // array union
$answer=$answer+qa_page_q_post_rules($answer, $question, $qchildposts, $achildposts); $answer=$answer+qa_page_q_post_rules($answer, $question, $qchildposts, $achildposts);
foreach ($achildposts as $key => $achildpost) foreach ($achildposts as $key => $achildpost)
$achildposts[$key]=$achildpost+qa_page_q_post_rules($achildpost, $answer, $achildposts, null); $achildposts[$key]=$achildpost+qa_page_q_post_rules($achildpost, $answer, $achildposts, null);
$usershtml=qa_userids_handles_html(array_merge(array($answer), $achildposts), true); $usershtml=qa_userids_handles_html(array_merge(array($answer), $achildposts), true);
$a_view=qa_page_q_answer_view($question, $answer, ($answer['postid']==$question['selchildid']) && ($answer['type']=='A'), $a_view=qa_page_q_answer_view($question, $answer, ($answer['postid']==$question['selchildid']) && ($answer['type']=='A'),
$usershtml, false); $usershtml, false);
$a_view['c_list']=qa_page_q_comment_follow_list($question, $answer, $achildposts, false, $usershtml, false, null); $a_view['c_list']=qa_page_q_comment_follow_list($question, $answer, $achildposts, false, $usershtml, false, null);
$themeclass=qa_load_theme_class(qa_get_site_theme(), 'ajax-answer', null, null); $themeclass=qa_load_theme_class(qa_get_site_theme(), 'ajax-answer', null, null);
// ... send back the HTML for it // ... send back the HTML for it
echo "\n"; echo "\n";
$themeclass->a_list_item($a_view); $themeclass->a_list_item($a_view);
} }
return; return;
} }
} }
echo "QA_AJAX_RESPONSE\n0\n"; // fall back to non-Ajax submission if something failed echo "QA_AJAX_RESPONSE\n0\n"; // fall back to non-Ajax submission if something failed
/* /*
Omit PHP closing tag to help avoid accidental output Omit PHP closing tag to help avoid accidental output
*/ */
\ No newline at end of file
<?php <?php
/* /*
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-include/qa-ajax-click-comment.php File: qa-include/qa-ajax-click-comment.php
Version: See define()s at top of qa-include/qa-base.php Version: See define()s at top of qa-include/qa-base.php
Description: Server-side response to Ajax single clicks on comments Description: Server-side response to Ajax single clicks on comments
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
require_once QA_INCLUDE_DIR.'qa-app-cookies.php'; require_once QA_INCLUDE_DIR.'qa-app-cookies.php';
require_once QA_INCLUDE_DIR.'qa-app-format.php'; require_once QA_INCLUDE_DIR.'qa-app-format.php';
require_once QA_INCLUDE_DIR.'qa-app-users.php'; require_once QA_INCLUDE_DIR.'qa-app-users.php';
require_once QA_INCLUDE_DIR.'qa-db-selects.php'; require_once QA_INCLUDE_DIR.'qa-db-selects.php';
require_once QA_INCLUDE_DIR.'qa-page-question-view.php'; require_once QA_INCLUDE_DIR.'qa-page-question-view.php';
require_once QA_INCLUDE_DIR.'qa-page-question-submit.php'; require_once QA_INCLUDE_DIR.'qa-page-question-submit.php';
// Load relevant information about this comment // Load relevant information about this comment
$commentid=qa_post_text('commentid'); $commentid=qa_post_text('commentid');
$questionid=qa_post_text('questionid'); $questionid=qa_post_text('questionid');
$parentid=qa_post_text('parentid'); $parentid=qa_post_text('parentid');
$userid=qa_get_logged_in_userid(); $userid=qa_get_logged_in_userid();
list($comment, $question, $parent, $children)=qa_db_select_with_pending( list($comment, $question, $parent, $children)=qa_db_select_with_pending(
qa_db_full_post_selectspec($userid, $commentid), qa_db_full_post_selectspec($userid, $commentid),
qa_db_full_post_selectspec($userid, $questionid), qa_db_full_post_selectspec($userid, $questionid),
qa_db_full_post_selectspec($userid, $parentid), qa_db_full_post_selectspec($userid, $parentid),
qa_db_full_child_posts_selectspec($userid, $parentid) qa_db_full_child_posts_selectspec($userid, $parentid)
); );
// Check if there was an operation that succeeded // Check if there was an operation that succeeded
if ( if (
(@$comment['basetype']=='C') && (@$comment['basetype']=='C') &&
(@$question['basetype']=='Q') && (@$question['basetype']=='Q') &&
((@$parent['basetype']=='Q') || (@$parent['basetype']=='A')) ((@$parent['basetype']=='Q') || (@$parent['basetype']=='A'))
) { ) {
$comment=$comment+qa_page_q_post_rules($comment, $parent, $children, null); // array union $comment=$comment+qa_page_q_post_rules($comment, $parent, $children, null); // array union
if (qa_page_q_single_click_c($comment, $question, $parent, $error)) { if (qa_page_q_single_click_c($comment, $question, $parent, $error)) {
$comment=qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $commentid)); $comment=qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $commentid));
// If so, page content to be updated via Ajax // If so, page content to be updated via Ajax
echo "QA_AJAX_RESPONSE\n1"; echo "QA_AJAX_RESPONSE\n1";
// If the comment was not deleted... // If the comment was not deleted...
if (isset($comment)) { if (isset($comment)) {
$parent=$parent+qa_page_q_post_rules($parent, ($questionid==$parentid) ? null : $question, null, $children); $parent=$parent+qa_page_q_post_rules($parent, ($questionid==$parentid) ? null : $question, null, $children);
// in theory we should retrieve the parent's siblings for the above, but they're not going to be relevant // in theory we should retrieve the parent's siblings for the above, but they're not going to be relevant
$comment=$comment+qa_page_q_post_rules($comment, $parent, $children, null); $comment=$comment+qa_page_q_post_rules($comment, $parent, $children, null);
$usershtml=qa_userids_handles_html(array($comment), true); $usershtml=qa_userids_handles_html(array($comment), true);
$c_view=qa_page_q_comment_view($question, $parent, $comment, $usershtml, false); $c_view=qa_page_q_comment_view($question, $parent, $comment, $usershtml, false);
$themeclass=qa_load_theme_class(qa_get_site_theme(), 'ajax-comment', null, null); $themeclass=qa_load_theme_class(qa_get_site_theme(), 'ajax-comment', null, null);
// ... send back the HTML for it // ... send back the HTML for it
echo "\n"; echo "\n";
$themeclass->c_list_item($c_view); $themeclass->c_list_item($c_view);
} }
return; return;
} }
} }
echo "QA_AJAX_RESPONSE\n0\n"; // fall back to non-Ajax submission if something failed echo "QA_AJAX_RESPONSE\n0\n"; // fall back to non-Ajax submission if something failed
/* /*
Omit PHP closing tag to help avoid accidental output Omit PHP closing tag to help avoid accidental output
*/ */
\ No newline at end of file
<?php <?php
/* /*
Question2Answer (c) Gideon Greenspan Question2Answer (c) Gideon Greenspan
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-include/qa-ajax-click-pm.php File: qa-include/qa-ajax-click-pm.php
Version: See define()s at top of qa-include/qa-base.php Version: See define()s at top of qa-include/qa-base.php
Description: Server-side response to Ajax single clicks on private messages Description: Server-side response to Ajax single clicks on private messages
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
require_once QA_INCLUDE_DIR.'qa-app-messages.php'; require_once QA_INCLUDE_DIR.'qa-app-messages.php';
require_once QA_INCLUDE_DIR.'qa-app-users.php'; require_once QA_INCLUDE_DIR.'qa-app-users.php';
require_once QA_INCLUDE_DIR.'qa-app-cookies.php'; require_once QA_INCLUDE_DIR.'qa-app-cookies.php';
require_once QA_INCLUDE_DIR.'qa-db-selects.php'; require_once QA_INCLUDE_DIR.'qa-db-selects.php';
$loginUserId = qa_get_logged_in_userid(); $loginUserId = qa_get_logged_in_userid();
$loginUserHandle = qa_get_logged_in_handle(); $loginUserHandle = qa_get_logged_in_handle();
$fromhandle = qa_post_text('handle'); $fromhandle = qa_post_text('handle');
$start = (int) qa_post_text('start'); $start = (int) qa_post_text('start');
$box = qa_post_text('box'); $box = qa_post_text('box');
$pagesize = qa_opt('page_size_pms'); $pagesize = qa_opt('page_size_pms');
if ( !isset($loginUserId) || $loginUserHandle !== $fromhandle || !in_array($box, array('inbox', 'outbox')) ) { if ( !isset($loginUserId) || $loginUserHandle !== $fromhandle || !in_array($box, array('inbox', 'outbox')) ) {
echo "QA_AJAX_RESPONSE\n0\n"; echo "QA_AJAX_RESPONSE\n0\n";
return; return;
} }
$func = 'qa_db_messages_'.$box.'_selectspec'; $func = 'qa_db_messages_'.$box.'_selectspec';
$pmSpec = $func('private', $loginUserId, true, $start, $pagesize); $pmSpec = $func('private', $loginUserId, true, $start, $pagesize);
$userMessages = qa_db_select_with_pending($pmSpec); $userMessages = qa_db_select_with_pending($pmSpec);
foreach ($userMessages as $message) { foreach ($userMessages as $message) {
if (qa_clicked('m'.$message['messageid'].'_dodelete')) { if (qa_clicked('m'.$message['messageid'].'_dodelete')) {
if (qa_check_form_security_code('pm-'.$fromhandle, qa_post_text('code'))) { if (qa_check_form_security_code('pm-'.$fromhandle, qa_post_text('code'))) {
qa_pm_delete($loginUserId, qa_get_logged_in_handle(), qa_cookie_get(), $message, $box); qa_pm_delete($loginUserId, qa_get_logged_in_handle(), qa_cookie_get(), $message, $box);
echo "QA_AJAX_RESPONSE\n1\n"; echo "QA_AJAX_RESPONSE\n1\n";
return; return;
} }
} }
} }
echo "QA_AJAX_RESPONSE\n0\n"; echo "QA_AJAX_RESPONSE\n0\n";
<?php <?php
/* /*
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-include/qa-ajax-click-wall.php File: qa-include/qa-ajax-click-wall.php
Version: See define()s at top of qa-include/qa-base.php Version: See define()s at top of qa-include/qa-base.php
Description: Server-side response to Ajax single clicks on wall posts Description: Server-side response to Ajax single clicks on wall posts
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
require_once QA_INCLUDE_DIR.'qa-app-messages.php'; require_once QA_INCLUDE_DIR.'qa-app-messages.php';
require_once QA_INCLUDE_DIR.'qa-app-users.php'; require_once QA_INCLUDE_DIR.'qa-app-users.php';
require_once QA_INCLUDE_DIR.'qa-app-cookies.php'; require_once QA_INCLUDE_DIR.'qa-app-cookies.php';
require_once QA_INCLUDE_DIR.'qa-db-selects.php'; require_once QA_INCLUDE_DIR.'qa-db-selects.php';
$tohandle=qa_post_text('handle'); $tohandle=qa_post_text('handle');
$start=(int)qa_post_text('start'); $start=(int)qa_post_text('start');
$usermessages=qa_db_select_with_pending(qa_db_recent_messages_selectspec(null, null, $tohandle, false, null, $start)); $usermessages=qa_db_select_with_pending(qa_db_recent_messages_selectspec(null, null, $tohandle, false, null, $start));
$usermessages=qa_wall_posts_add_rules($usermessages, $start); $usermessages=qa_wall_posts_add_rules($usermessages, $start);
foreach ($usermessages as $message) foreach ($usermessages as $message)
if (qa_clicked('m'.$message['messageid'].'_dodelete') && $message['deleteable']) if (qa_clicked('m'.$message['messageid'].'_dodelete') && $message['deleteable'])
if (qa_check_form_security_code('wall-'.$tohandle, qa_post_text('code'))) { if (qa_check_form_security_code('wall-'.$tohandle, qa_post_text('code'))) {
qa_wall_delete_post(qa_get_logged_in_userid(), qa_get_logged_in_handle(), qa_cookie_get(), $message); qa_wall_delete_post(qa_get_logged_in_userid(), qa_get_logged_in_handle(), qa_cookie_get(), $message);
echo "QA_AJAX_RESPONSE\n1\n"; echo "QA_AJAX_RESPONSE\n1\n";
return; return;
} }
echo "QA_AJAX_RESPONSE\n0\n"; echo "QA_AJAX_RESPONSE\n0\n";
/* /*
Omit PHP closing tag to help avoid accidental output Omit PHP closing tag to help avoid accidental output
*/ */
\ No newline at end of file
<?php <?php
/* /*
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-include/qa-ajax-comment.php File: qa-include/qa-ajax-comment.php
Version: See define()s at top of qa-include/qa-base.php Version: See define()s at top of qa-include/qa-base.php
Description: Server-side response to Ajax create comment requests Description: Server-side response to Ajax create comment requests
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
require_once QA_INCLUDE_DIR.'qa-app-users.php'; require_once QA_INCLUDE_DIR.'qa-app-users.php';
require_once QA_INCLUDE_DIR.'qa-app-limits.php'; require_once QA_INCLUDE_DIR.'qa-app-limits.php';
require_once QA_INCLUDE_DIR.'qa-db-selects.php'; require_once QA_INCLUDE_DIR.'qa-db-selects.php';
// Load relevant information about this question and the comment parent // Load relevant information about this question and the comment parent
$questionid=qa_post_text('c_questionid'); $questionid=qa_post_text('c_questionid');
$parentid=qa_post_text('c_parentid'); $parentid=qa_post_text('c_parentid');
$userid=qa_get_logged_in_userid(); $userid=qa_get_logged_in_userid();
list($question, $parent, $children)=qa_db_select_with_pending( list($question, $parent, $children)=qa_db_select_with_pending(
qa_db_full_post_selectspec($userid, $questionid), qa_db_full_post_selectspec($userid, $questionid),
qa_db_full_post_selectspec($userid, $parentid), qa_db_full_post_selectspec($userid, $parentid),
qa_db_full_child_posts_selectspec($userid, $parentid) qa_db_full_child_posts_selectspec($userid, $parentid)
); );
// Check if the question and parent exist, and whether the user has permission to do this // Check if the question and parent exist, and whether the user has permission to do this
if ( if (
(@$question['basetype']=='Q') && (@$question['basetype']=='Q') &&
((@$parent['basetype']=='Q') || (@$parent['basetype']=='A')) && ((@$parent['basetype']=='Q') || (@$parent['basetype']=='A')) &&
!qa_user_post_permit_error('permit_post_c', $parent, QA_LIMIT_COMMENTS)) !qa_user_post_permit_error('permit_post_c', $parent, QA_LIMIT_COMMENTS))
{ {
require_once QA_INCLUDE_DIR.'qa-app-captcha.php'; require_once QA_INCLUDE_DIR.'qa-app-captcha.php';
require_once QA_INCLUDE_DIR.'qa-app-format.php'; require_once QA_INCLUDE_DIR.'qa-app-format.php';
require_once QA_INCLUDE_DIR.'qa-app-post-create.php'; require_once QA_INCLUDE_DIR.'qa-app-post-create.php';
require_once QA_INCLUDE_DIR.'qa-app-cookies.php'; require_once QA_INCLUDE_DIR.'qa-app-cookies.php';
require_once QA_INCLUDE_DIR.'qa-page-question-view.php'; require_once QA_INCLUDE_DIR.'qa-page-question-view.php';
require_once QA_INCLUDE_DIR.'qa-page-question-submit.php'; require_once QA_INCLUDE_DIR.'qa-page-question-submit.php';
require_once QA_INCLUDE_DIR.'qa-util-sort.php'; require_once QA_INCLUDE_DIR.'qa-util-sort.php';
// Try to create the new comment // Try to create the new comment
$usecaptcha=qa_user_use_captcha(qa_user_level_for_post($question)); $usecaptcha=qa_user_use_captcha(qa_user_level_for_post($question));
$commentid=qa_page_q_add_c_submit($question, $parent, $children, $usecaptcha, $in, $errors); $commentid=qa_page_q_add_c_submit($question, $parent, $children, $usecaptcha, $in, $errors);
// If successful, page content will be updated via Ajax // If successful, page content will be updated via Ajax
if (isset($commentid)) { if (isset($commentid)) {
$children=qa_db_select_with_pending(qa_db_full_child_posts_selectspec($userid, $parentid)); $children=qa_db_select_with_pending(qa_db_full_child_posts_selectspec($userid, $parentid));
$parent=$parent+qa_page_q_post_rules($parent, ($questionid==$parentid) ? null : $question, null, $children); $parent=$parent+qa_page_q_post_rules($parent, ($questionid==$parentid) ? null : $question, null, $children);
// in theory we should retrieve the parent's siblings for the above, but they're not going to be relevant // in theory we should retrieve the parent's siblings for the above, but they're not going to be relevant
foreach ($children as $key => $child) foreach ($children as $key => $child)
$children[$key]=$child+qa_page_q_post_rules($child, $parent, $children, null); $children[$key]=$child+qa_page_q_post_rules($child, $parent, $children, null);
$usershtml=qa_userids_handles_html($children, true); $usershtml=qa_userids_handles_html($children, true);
qa_sort_by($children, 'created'); qa_sort_by($children, 'created');
$c_list=qa_page_q_comment_follow_list($question, $parent, $children, true, $usershtml, false, null); $c_list=qa_page_q_comment_follow_list($question, $parent, $children, true, $usershtml, false, null);
$themeclass=qa_load_theme_class(qa_get_site_theme(), 'ajax-comments', null, null); $themeclass=qa_load_theme_class(qa_get_site_theme(), 'ajax-comments', null, null);
echo "QA_AJAX_RESPONSE\n1\n"; echo "QA_AJAX_RESPONSE\n1\n";
// Send back the ID of the new comment // Send back the ID of the new comment
echo qa_anchor('C', $commentid)."\n"; echo qa_anchor('C', $commentid)."\n";
// Send back the HTML // Send back the HTML
$themeclass->c_list_items($c_list['cs']); $themeclass->c_list_items($c_list['cs']);
return; return;
} }
} }
echo "QA_AJAX_RESPONSE\n0\n"; // fall back to non-Ajax submission if there were any problems echo "QA_AJAX_RESPONSE\n0\n"; // fall back to non-Ajax submission if there were any problems
/* /*
Omit PHP closing tag to help avoid accidental output Omit PHP closing tag to help avoid accidental output
*/ */
\ No newline at end of file
<?php <?php
/* /*
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-include/qa-ajax-favorite.php File: qa-include/qa-ajax-favorite.php
Version: See define()s at top of qa-include/qa-base.php Version: See define()s at top of qa-include/qa-base.php
Description: Server-side response to Ajax favorite requests Description: Server-side response to Ajax favorite requests
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
require_once QA_INCLUDE_DIR.'qa-app-users.php'; require_once QA_INCLUDE_DIR.'qa-app-users.php';
require_once QA_INCLUDE_DIR.'qa-app-cookies.php'; require_once QA_INCLUDE_DIR.'qa-app-cookies.php';
require_once QA_INCLUDE_DIR.'qa-app-favorites.php'; require_once QA_INCLUDE_DIR.'qa-app-favorites.php';
require_once QA_INCLUDE_DIR.'qa-app-format.php'; require_once QA_INCLUDE_DIR.'qa-app-format.php';
$entitytype=qa_post_text('entitytype'); $entitytype=qa_post_text('entitytype');
$entityid=qa_post_text('entityid'); $entityid=qa_post_text('entityid');
$setfavorite=qa_post_text('favorite'); $setfavorite=qa_post_text('favorite');
$userid=qa_get_logged_in_userid(); $userid=qa_get_logged_in_userid();
if (!qa_check_form_security_code('favorite-'.$entitytype.'-'.$entityid, qa_post_text('code'))) if (!qa_check_form_security_code('favorite-'.$entitytype.'-'.$entityid, qa_post_text('code')))
echo "QA_AJAX_RESPONSE\n0\n".qa_lang('misc/form_security_reload'); echo "QA_AJAX_RESPONSE\n0\n".qa_lang('misc/form_security_reload');
elseif (isset($userid)) { elseif (isset($userid)) {
$cookieid=qa_cookie_get(); $cookieid=qa_cookie_get();
qa_user_favorite_set($userid, qa_get_logged_in_handle(), $cookieid, $entitytype, $entityid, $setfavorite); qa_user_favorite_set($userid, qa_get_logged_in_handle(), $cookieid, $entitytype, $entityid, $setfavorite);
$favoriteform=qa_favorite_form($entitytype, $entityid, $setfavorite, qa_lang($setfavorite ? 'main/remove_favorites' : 'main/add_favorites')); $favoriteform=qa_favorite_form($entitytype, $entityid, $setfavorite, qa_lang($setfavorite ? 'main/remove_favorites' : 'main/add_favorites'));
$themeclass=qa_load_theme_class(qa_get_site_theme(), 'ajax-favorite', null, null); $themeclass=qa_load_theme_class(qa_get_site_theme(), 'ajax-favorite', null, null);
echo "QA_AJAX_RESPONSE\n1\n"; echo "QA_AJAX_RESPONSE\n1\n";
$themeclass->favorite_inner_html($favoriteform); $themeclass->favorite_inner_html($favoriteform);
} }
/* /*
Omit PHP closing tag to help avoid accidental output Omit PHP closing tag to help avoid accidental output
*/ */
\ No newline at end of file
<?php <?php
/* /*
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-include/qa-ajax-mailing.php File: qa-include/qa-ajax-mailing.php
Version: See define()s at top of qa-include/qa-base.php Version: See define()s at top of qa-include/qa-base.php
Description: Server-side response to Ajax mailing loop requests Description: Server-side response to Ajax mailing loop requests
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
require_once QA_INCLUDE_DIR.'qa-app-users.php'; require_once QA_INCLUDE_DIR.'qa-app-users.php';
require_once QA_INCLUDE_DIR.'qa-app-mailing.php'; require_once QA_INCLUDE_DIR.'qa-app-mailing.php';
$continue=false; $continue=false;
if (qa_get_logged_in_level()>=QA_USER_LEVEL_ADMIN) { if (qa_get_logged_in_level()>=QA_USER_LEVEL_ADMIN) {
$starttime=time(); $starttime=time();
qa_mailing_perform_step(); qa_mailing_perform_step();
if ($starttime==time()) if ($starttime==time())
sleep(1); // make sure at least one second has passed sleep(1); // make sure at least one second has passed
$message=qa_mailing_progress_message(); $message=qa_mailing_progress_message();
if (isset($message)) if (isset($message))
$continue=true; $continue=true;
else else
$message=qa_lang('admin/mailing_complete'); $message=qa_lang('admin/mailing_complete');
} else } else
$message=qa_lang('admin/no_privileges'); $message=qa_lang('admin/no_privileges');
echo "QA_AJAX_RESPONSE\n".(int)$continue."\n".qa_html($message); echo "QA_AJAX_RESPONSE\n".(int)$continue."\n".qa_html($message);
/* /*
Omit PHP closing tag to help avoid accidental output Omit PHP closing tag to help avoid accidental output
*/ */
\ No newline at end of file
<?php <?php
/* /*
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-include/qa-ajax-notice.php File: qa-include/qa-ajax-notice.php
Version: See define()s at top of qa-include/qa-base.php Version: See define()s at top of qa-include/qa-base.php
Description: Server-side response to Ajax requests to close a notice Description: Server-side response to Ajax requests to close a notice
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
require_once QA_INCLUDE_DIR.'qa-app-users.php'; require_once QA_INCLUDE_DIR.'qa-app-users.php';
require_once QA_INCLUDE_DIR.'qa-db-notices.php'; require_once QA_INCLUDE_DIR.'qa-db-notices.php';
require_once QA_INCLUDE_DIR.'qa-db-users.php'; require_once QA_INCLUDE_DIR.'qa-db-users.php';
$noticeid=qa_post_text('noticeid'); $noticeid=qa_post_text('noticeid');
if (!qa_check_form_security_code('notice-'.$noticeid, qa_post_text('code'))) if (!qa_check_form_security_code('notice-'.$noticeid, qa_post_text('code')))
echo "QA_AJAX_RESPONSE\n0\n".qa_lang('misc/form_security_reload'); echo "QA_AJAX_RESPONSE\n0\n".qa_lang('misc/form_security_reload');
else { else {
if ($noticeid=='visitor') if ($noticeid=='visitor')
setcookie('qa_noticed', 1, time()+86400*3650, '/', QA_COOKIE_DOMAIN); setcookie('qa_noticed', 1, time()+86400*3650, '/', QA_COOKIE_DOMAIN);
else { else {
$userid=qa_get_logged_in_userid(); $userid=qa_get_logged_in_userid();
if ($noticeid=='welcome') if ($noticeid=='welcome')
qa_db_user_set_flag($userid, QA_USER_FLAGS_WELCOME_NOTICE, false); qa_db_user_set_flag($userid, QA_USER_FLAGS_WELCOME_NOTICE, false);
else else
qa_db_usernotice_delete($userid, $noticeid); qa_db_usernotice_delete($userid, $noticeid);
} }
echo "QA_AJAX_RESPONSE\n1"; echo "QA_AJAX_RESPONSE\n1";
} }
/* /*
Omit PHP closing tag to help avoid accidental output Omit PHP closing tag to help avoid accidental output
*/ */
\ No newline at end of file
<?php <?php
/* /*
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-include/qa-ajax-recalc.php File: qa-include/qa-ajax-recalc.php
Version: See define()s at top of qa-include/qa-base.php Version: See define()s at top of qa-include/qa-base.php
Description: Server-side response to Ajax admin recalculation requests Description: Server-side response to Ajax admin recalculation requests
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
require_once QA_INCLUDE_DIR.'qa-app-users.php'; require_once QA_INCLUDE_DIR.'qa-app-users.php';
require_once QA_INCLUDE_DIR.'qa-app-recalc.php'; require_once QA_INCLUDE_DIR.'qa-app-recalc.php';
if (qa_get_logged_in_level()>=QA_USER_LEVEL_ADMIN) { if (qa_get_logged_in_level()>=QA_USER_LEVEL_ADMIN) {
if (!qa_check_form_security_code('admin/recalc', qa_post_text('code'))) { if (!qa_check_form_security_code('admin/recalc', qa_post_text('code'))) {
$state=''; $state='';
$message=qa_lang('misc/form_security_reload'); $message=qa_lang('misc/form_security_reload');
} else { } else {
$state=qa_post_text('state'); $state=qa_post_text('state');
$stoptime=time()+3; $stoptime=time()+3;
while ( qa_recalc_perform_step($state) && (time()<$stoptime) ) while ( qa_recalc_perform_step($state) && (time()<$stoptime) )
; ;
$message=qa_recalc_get_message($state); $message=qa_recalc_get_message($state);
} }
} else { } else {
$state=''; $state='';
$message=qa_lang('admin/no_privileges'); $message=qa_lang('admin/no_privileges');
} }
echo "QA_AJAX_RESPONSE\n1\n".$state."\n".qa_html($message); echo "QA_AJAX_RESPONSE\n1\n".$state."\n".qa_html($message);
/* /*
Omit PHP closing tag to help avoid accidental output Omit PHP closing tag to help avoid accidental output
*/ */
\ No newline at end of file
<?php <?php
/* /*
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-include/qa-ajax-show-comments.php File: qa-include/qa-ajax-show-comments.php
Version: See define()s at top of qa-include/qa-base.php Version: See define()s at top of qa-include/qa-base.php
Description: Server-side response to Ajax request to view full comment list Description: Server-side response to Ajax request to view full comment list
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
require_once QA_INCLUDE_DIR.'qa-db-selects.php'; require_once QA_INCLUDE_DIR.'qa-db-selects.php';
require_once QA_INCLUDE_DIR.'qa-app-users.php'; require_once QA_INCLUDE_DIR.'qa-app-users.php';
require_once QA_INCLUDE_DIR.'qa-app-cookies.php'; require_once QA_INCLUDE_DIR.'qa-app-cookies.php';
require_once QA_INCLUDE_DIR.'qa-app-format.php'; require_once QA_INCLUDE_DIR.'qa-app-format.php';
require_once QA_INCLUDE_DIR.'qa-page-question-view.php'; require_once QA_INCLUDE_DIR.'qa-page-question-view.php';
require_once QA_INCLUDE_DIR.'qa-util-sort.php'; require_once QA_INCLUDE_DIR.'qa-util-sort.php';
// Load relevant information about this question and check it exists // Load relevant information about this question and check it exists
$questionid=qa_post_text('c_questionid'); $questionid=qa_post_text('c_questionid');
$parentid=qa_post_text('c_parentid'); $parentid=qa_post_text('c_parentid');
$userid=qa_get_logged_in_userid(); $userid=qa_get_logged_in_userid();
list($question, $parent, $children)=qa_db_select_with_pending( list($question, $parent, $children)=qa_db_select_with_pending(
qa_db_full_post_selectspec($userid, $questionid), qa_db_full_post_selectspec($userid, $questionid),
qa_db_full_post_selectspec($userid, $parentid), qa_db_full_post_selectspec($userid, $parentid),
qa_db_full_child_posts_selectspec($userid, $parentid) qa_db_full_child_posts_selectspec($userid, $parentid)
); );
if (isset($parent)) { if (isset($parent)) {
$parent=$parent+qa_page_q_post_rules($parent, null, null, $children); $parent=$parent+qa_page_q_post_rules($parent, null, null, $children);
// in theory we should retrieve the parent's parent and siblings for the above, but they're not going to be relevant // in theory we should retrieve the parent's parent and siblings for the above, but they're not going to be relevant
foreach ($children as $key => $child) foreach ($children as $key => $child)
$children[$key]=$child+qa_page_q_post_rules($child, $parent, $children, null); $children[$key]=$child+qa_page_q_post_rules($child, $parent, $children, null);
$usershtml=qa_userids_handles_html($children, true); $usershtml=qa_userids_handles_html($children, true);
qa_sort_by($children, 'created'); qa_sort_by($children, 'created');
$c_list=qa_page_q_comment_follow_list($question, $parent, $children, true, $usershtml, false, null); $c_list=qa_page_q_comment_follow_list($question, $parent, $children, true, $usershtml, false, null);
$themeclass=qa_load_theme_class(qa_get_site_theme(), 'ajax-comments', null, null); $themeclass=qa_load_theme_class(qa_get_site_theme(), 'ajax-comments', null, null);
echo "QA_AJAX_RESPONSE\n1\n"; echo "QA_AJAX_RESPONSE\n1\n";
// Send back the HTML // Send back the HTML
$themeclass->c_list_items($c_list['cs']); $themeclass->c_list_items($c_list['cs']);
return; return;
} }
echo "QA_AJAX_RESPONSE\n0\n"; echo "QA_AJAX_RESPONSE\n0\n";
/* /*
Omit PHP closing tag to help avoid accidental output Omit PHP closing tag to help avoid accidental output
*/ */
\ No newline at end of file
<?php <?php
/* /*
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-include/qa-ajax-version.php File: qa-include/qa-ajax-version.php
Version: See define()s at top of qa-include/qa-base.php Version: See define()s at top of qa-include/qa-base.php
Description: Server-side response to Ajax version check requests Description: Server-side response to Ajax version check requests
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
require_once QA_INCLUDE_DIR.'qa-app-admin.php'; require_once QA_INCLUDE_DIR.'qa-app-admin.php';
$uri = qa_post_text('uri'); $uri = qa_post_text('uri');
$type = (qa_post_text('type') === 'Theme' ? 'Theme' : 'Plugin'); $type = (qa_post_text('type') === 'Theme' ? 'Theme' : 'Plugin');
$version = qa_post_text('version'); $version = qa_post_text('version');
$metadata = qa_addon_metadata(qa_retrieve_url($uri), $type); $metadata = qa_addon_metadata(qa_retrieve_url($uri), $type);
if (strlen(@$metadata['version'])) { if (strlen(@$metadata['version'])) {
if (strcmp($metadata['version'], $version)) { if (strcmp($metadata['version'], $version)) {
if (qa_qa_version_below(@$metadata['min_q2a'])) { if (qa_qa_version_below(@$metadata['min_q2a'])) {
$response = strtr(qa_lang_html('admin/version_requires_q2a'), array( $response = strtr(qa_lang_html('admin/version_requires_q2a'), array(
'^1' => qa_html('v'.$metadata['version']), '^1' => qa_html('v'.$metadata['version']),
'^2' => qa_html($metadata['min_q2a']), '^2' => qa_html($metadata['min_q2a']),
)); ));
} }
elseif (qa_php_version_below(@$metadata['min_php'])) { elseif (qa_php_version_below(@$metadata['min_php'])) {
$response = strtr(qa_lang_html('admin/version_requires_php'), array( $response = strtr(qa_lang_html('admin/version_requires_php'), array(
'^1' => qa_html('v'.$metadata['version']), '^1' => qa_html('v'.$metadata['version']),
'^2' => qa_html($metadata['min_php']), '^2' => qa_html($metadata['min_php']),
)); ));
} }
else { else {
$response = qa_lang_html_sub('admin/version_get_x', qa_html('v'.$metadata['version'])); $response = qa_lang_html_sub('admin/version_get_x', qa_html('v'.$metadata['version']));
if (strlen(@$metadata['uri'])) if (strlen(@$metadata['uri']))
$response = '<a href="'.qa_html($metadata['uri']).'" style="color:#d00;">'.$response.'</a>'; $response = '<a href="'.qa_html($metadata['uri']).'" style="color:#d00;">'.$response.'</a>';
} }
} }
else else
$response = qa_lang_html('admin/version_latest'); $response = qa_lang_html('admin/version_latest');
} }
else else
$response = qa_lang_html('admin/version_latest_unknown'); $response = qa_lang_html('admin/version_latest_unknown');
echo "QA_AJAX_RESPONSE\n1\n".$response; echo "QA_AJAX_RESPONSE\n1\n".$response;
/* /*
Omit PHP closing tag to help avoid accidental output Omit PHP closing tag to help avoid accidental output
*/ */
\ No newline at end of file
<?php <?php
/* /*
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-include/qa-ajax-vote.php File: qa-include/qa-ajax-vote.php
Version: See define()s at top of qa-include/qa-base.php Version: See define()s at top of qa-include/qa-base.php
Description: Server-side response to Ajax voting requests Description: Server-side response to Ajax voting requests
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
require_once QA_INCLUDE_DIR.'qa-app-users.php'; require_once QA_INCLUDE_DIR.'qa-app-users.php';
require_once QA_INCLUDE_DIR.'qa-app-cookies.php'; require_once QA_INCLUDE_DIR.'qa-app-cookies.php';
require_once QA_INCLUDE_DIR.'qa-app-votes.php'; require_once QA_INCLUDE_DIR.'qa-app-votes.php';
require_once QA_INCLUDE_DIR.'qa-app-format.php'; require_once QA_INCLUDE_DIR.'qa-app-format.php';
require_once QA_INCLUDE_DIR.'qa-app-options.php'; require_once QA_INCLUDE_DIR.'qa-app-options.php';
require_once QA_INCLUDE_DIR.'qa-db-selects.php'; require_once QA_INCLUDE_DIR.'qa-db-selects.php';
$postid=qa_post_text('postid'); $postid=qa_post_text('postid');
$vote=qa_post_text('vote'); $vote=qa_post_text('vote');
$code=qa_post_text('code'); $code=qa_post_text('code');
$userid=qa_get_logged_in_userid(); $userid=qa_get_logged_in_userid();
$cookieid=qa_cookie_get(); $cookieid=qa_cookie_get();
if (!qa_check_form_security_code('vote', $code)) if (!qa_check_form_security_code('vote', $code))
$voteerror=qa_lang_html('misc/form_security_reload'); $voteerror=qa_lang_html('misc/form_security_reload');
else { else {
$post=qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $postid)); $post=qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $postid));
$voteerror=qa_vote_error_html($post, $vote, $userid, qa_request()); $voteerror=qa_vote_error_html($post, $vote, $userid, qa_request());
} }
if ($voteerror===false) { if ($voteerror===false) {
qa_vote_set($post, $userid, qa_get_logged_in_handle(), $cookieid, $vote); qa_vote_set($post, $userid, qa_get_logged_in_handle(), $cookieid, $vote);
$post=qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $postid)); $post=qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $postid));
$fields=qa_post_html_fields($post, $userid, $cookieid, array(), null, array( $fields=qa_post_html_fields($post, $userid, $cookieid, array(), null, array(
'voteview' => qa_get_vote_view($post, true), // behave as if on question page since the vote succeeded 'voteview' => qa_get_vote_view($post, true), // behave as if on question page since the vote succeeded
)); ));
$themeclass=qa_load_theme_class(qa_get_site_theme(), 'voting', null, null); $themeclass=qa_load_theme_class(qa_get_site_theme(), 'voting', null, null);
echo "QA_AJAX_RESPONSE\n1\n"; echo "QA_AJAX_RESPONSE\n1\n";
$themeclass->voting_inner_html($fields); $themeclass->voting_inner_html($fields);
} else } else
echo "QA_AJAX_RESPONSE\n0\n".$voteerror; echo "QA_AJAX_RESPONSE\n0\n".$voteerror;
/* /*
Omit PHP closing tag to help avoid accidental output Omit PHP closing tag to help avoid accidental output
*/ */
\ No newline at end of file
<?php <?php
/* /*
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-include/qa-ajax-wallpost.php File: qa-include/qa-ajax-wallpost.php
Version: See define()s at top of qa-include/qa-base.php Version: See define()s at top of qa-include/qa-base.php
Description: Server-side response to Ajax wall post requests Description: Server-side response to Ajax wall post requests
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
require_once QA_INCLUDE_DIR.'qa-app-messages.php'; require_once QA_INCLUDE_DIR.'qa-app-messages.php';
require_once QA_INCLUDE_DIR.'qa-app-users.php'; require_once QA_INCLUDE_DIR.'qa-app-users.php';
require_once QA_INCLUDE_DIR.'qa-app-cookies.php'; require_once QA_INCLUDE_DIR.'qa-app-cookies.php';
require_once QA_INCLUDE_DIR.'qa-db-selects.php'; require_once QA_INCLUDE_DIR.'qa-db-selects.php';
$message=qa_post_text('message'); $message=qa_post_text('message');
$tohandle=qa_post_text('handle'); $tohandle=qa_post_text('handle');
$morelink=qa_post_text('morelink'); $morelink=qa_post_text('morelink');
$touseraccount=qa_db_select_with_pending(qa_db_user_account_selectspec($tohandle, false)); $touseraccount=qa_db_select_with_pending(qa_db_user_account_selectspec($tohandle, false));
$loginuserid=qa_get_logged_in_userid(); $loginuserid=qa_get_logged_in_userid();
$errorhtml=qa_wall_error_html($loginuserid, $touseraccount['userid'], $touseraccount['flags']); $errorhtml=qa_wall_error_html($loginuserid, $touseraccount['userid'], $touseraccount['flags']);
if ($errorhtml || (!strlen($message)) || !qa_check_form_security_code('wall-'.$tohandle, qa_post_text('code')) ) if ($errorhtml || (!strlen($message)) || !qa_check_form_security_code('wall-'.$tohandle, qa_post_text('code')) )
echo "QA_AJAX_RESPONSE\n0"; // if there's an error, process in non-Ajax way echo "QA_AJAX_RESPONSE\n0"; // if there's an error, process in non-Ajax way
else { else {
$messageid=qa_wall_add_post($loginuserid, qa_get_logged_in_handle(), qa_cookie_get(), $messageid=qa_wall_add_post($loginuserid, qa_get_logged_in_handle(), qa_cookie_get(),
$touseraccount['userid'], $touseraccount['handle'], $message, ''); $touseraccount['userid'], $touseraccount['handle'], $message, '');
$touseraccount['wallposts']++; // won't have been updated $touseraccount['wallposts']++; // won't have been updated
$usermessages=qa_db_select_with_pending(qa_db_recent_messages_selectspec(null, null, $touseraccount['userid'], true, qa_opt('page_size_wall'))); $usermessages=qa_db_select_with_pending(qa_db_recent_messages_selectspec(null, null, $touseraccount['userid'], true, qa_opt('page_size_wall')));
$usermessages=qa_wall_posts_add_rules($usermessages, 0); $usermessages=qa_wall_posts_add_rules($usermessages, 0);
$themeclass=qa_load_theme_class(qa_get_site_theme(), 'wall', null, null); $themeclass=qa_load_theme_class(qa_get_site_theme(), 'wall', null, null);
echo "QA_AJAX_RESPONSE\n1\n"; echo "QA_AJAX_RESPONSE\n1\n";
echo 'm'.$messageid."\n"; // element in list to be revealed echo 'm'.$messageid."\n"; // element in list to be revealed
foreach ($usermessages as $message) foreach ($usermessages as $message)
$themeclass->message_item(qa_wall_post_view($message)); $themeclass->message_item(qa_wall_post_view($message));
if ($morelink && ($touseraccount['wallposts']>count($usermessages))) if ($morelink && ($touseraccount['wallposts']>count($usermessages)))
$themeclass->message_item(qa_wall_view_more_link($tohandle, count($usermessages))); $themeclass->message_item(qa_wall_view_more_link($tohandle, count($usermessages)));
} }
/* /*
Omit PHP closing tag to help avoid accidental output Omit PHP closing tag to help avoid accidental output
*/ */
\ No newline at end of file
<?php <?php
/* /*
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-include/qa-ajax.php File: qa-include/qa-ajax.php
Version: See define()s at top of qa-include/qa-base.php Version: See define()s at top of qa-include/qa-base.php
Description: Front line of response to Ajax requests, routing as appropriate Description: Front line of response to Ajax requests, routing as appropriate
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
// Output this header as early as possible // Output this header as early as possible
header('Content-Type: text/plain; charset=utf-8'); header('Content-Type: text/plain; charset=utf-8');
// Ensure no PHP errors are shown in the Ajax response // Ensure no PHP errors are shown in the Ajax response
@ini_set('display_errors', 0); @ini_set('display_errors', 0);
// Load the Q2A base file which sets up a bunch of crucial functions // Load the Q2A base file which sets up a bunch of crucial functions
require 'qa-base.php'; require 'qa-base.php';
qa_report_process_stage('init_ajax'); qa_report_process_stage('init_ajax');
// Get general Ajax parameters from the POST payload, and clear $_GET // Get general Ajax parameters from the POST payload, and clear $_GET
qa_set_request(qa_post_text('qa_request'), qa_post_text('qa_root')); qa_set_request(qa_post_text('qa_request'), qa_post_text('qa_root'));
$_GET=array(); // for qa_self_html() $_GET=array(); // for qa_self_html()
// Database failure handler // Database failure handler
function qa_ajax_db_fail_handler() function qa_ajax_db_fail_handler()
{ {
echo "QA_AJAX_RESPONSE\n0\nA database error occurred."; echo "QA_AJAX_RESPONSE\n0\nA database error occurred.";
qa_exit('error'); qa_exit('error');
} }
// Perform the appropriate Ajax operation // Perform the appropriate Ajax operation
$routing=array( $routing=array(
'notice' => 'qa-ajax-notice.php', 'notice' => 'qa-ajax-notice.php',
'favorite' => 'qa-ajax-favorite.php', 'favorite' => 'qa-ajax-favorite.php',
'vote' => 'qa-ajax-vote.php', 'vote' => 'qa-ajax-vote.php',
'recalc' => 'qa-ajax-recalc.php', 'recalc' => 'qa-ajax-recalc.php',
'mailing' => 'qa-ajax-mailing.php', 'mailing' => 'qa-ajax-mailing.php',
'version' => 'qa-ajax-version.php', 'version' => 'qa-ajax-version.php',
'category' => 'qa-ajax-category.php', 'category' => 'qa-ajax-category.php',
'asktitle' => 'qa-ajax-asktitle.php', 'asktitle' => 'qa-ajax-asktitle.php',
'answer' => 'qa-ajax-answer.php', 'answer' => 'qa-ajax-answer.php',
'comment' => 'qa-ajax-comment.php', 'comment' => 'qa-ajax-comment.php',
'click_a' => 'qa-ajax-click-answer.php', 'click_a' => 'qa-ajax-click-answer.php',
'click_c' => 'qa-ajax-click-comment.php', 'click_c' => 'qa-ajax-click-comment.php',
'click_admin' => 'qa-ajax-click-admin.php', 'click_admin' => 'qa-ajax-click-admin.php',
'show_cs' => 'qa-ajax-show-comments.php', 'show_cs' => 'qa-ajax-show-comments.php',
'wallpost' => 'qa-ajax-wallpost.php', 'wallpost' => 'qa-ajax-wallpost.php',
'click_wall' => 'qa-ajax-click-wall.php', 'click_wall' => 'qa-ajax-click-wall.php',
'click_pm' => 'qa-ajax-click-pm.php', 'click_pm' => 'qa-ajax-click-pm.php',
); );
$operation=qa_post_text('qa_operation'); $operation=qa_post_text('qa_operation');
if (isset($routing[$operation])) { if (isset($routing[$operation])) {
qa_db_connect('qa_ajax_db_fail_handler'); qa_db_connect('qa_ajax_db_fail_handler');
require QA_INCLUDE_DIR.$routing[$operation]; require QA_INCLUDE_DIR.$routing[$operation];
qa_db_disconnect(); qa_db_disconnect();
} }
/* /*
Omit PHP closing tag to help avoid accidental output Omit PHP closing tag to help avoid accidental output
*/ */
\ No newline at end of file
<?php <?php
/* /*
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-include/qa-app-captcha.php File: qa-include/qa-app-captcha.php
Version: See define()s at top of qa-include/qa-base.php Version: See define()s at top of qa-include/qa-base.php
Description: Wrapper functions and utilities for captcha modules Description: Wrapper functions and utilities for captcha modules
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../'); header('Location: ../');
exit; exit;
} }
function qa_captcha_available() function qa_captcha_available()
/* /*
Return whether a captcha module has been selected and it indicates that it is fully set up to go Return whether a captcha module has been selected and it indicates that it is fully set up to go
*/ */
{ {
$module=qa_load_module('captcha', qa_opt('captcha_module')); $module=qa_load_module('captcha', qa_opt('captcha_module'));
return isset($module) && ( (!method_exists($module, 'allow_captcha')) || $module->allow_captcha()); return isset($module) && ( (!method_exists($module, 'allow_captcha')) || $module->allow_captcha());
} }
function qa_captcha_reason_note($captchareason) function qa_captcha_reason_note($captchareason)
/* /*
Return an HTML string explaining $captchareason (from qa_user_captcha_reason()) to the user about why they are seeing a captcha Return an HTML string explaining $captchareason (from qa_user_captcha_reason()) to the user about why they are seeing a captcha
*/ */
{ {
$notehtml=null; $notehtml=null;
switch ($captchareason) { switch ($captchareason) {
case 'login': case 'login':
$notehtml=qa_insert_login_links(qa_lang_html('misc/captcha_login_fix')); $notehtml=qa_insert_login_links(qa_lang_html('misc/captcha_login_fix'));
break; break;
case 'confirm': case 'confirm':
$notehtml=qa_insert_login_links(qa_lang_html('misc/captcha_confirm_fix')); $notehtml=qa_insert_login_links(qa_lang_html('misc/captcha_confirm_fix'));
break; break;
case 'approve': case 'approve':
$notehtml=qa_lang_html('misc/captcha_approve_fix'); $notehtml=qa_lang_html('misc/captcha_approve_fix');
break; break;
} }
return $notehtml; return $notehtml;
} }
function qa_set_up_captcha_field(&$qa_content, &$fields, $errors, $note=null) function qa_set_up_captcha_field(&$qa_content, &$fields, $errors, $note=null)
/* /*
Prepare $qa_content for showing a captcha, adding the element to $fields, given previous $errors, and a $note to display Prepare $qa_content for showing a captcha, adding the element to $fields, given previous $errors, and a $note to display
*/ */
{ {
if (qa_captcha_available()) { if (qa_captcha_available()) {
$captcha=qa_load_module('captcha', qa_opt('captcha_module')); $captcha=qa_load_module('captcha', qa_opt('captcha_module'));
$count=@++$qa_content['qa_captcha_count']; // work around fact that reCAPTCHA can only display per page $count=@++$qa_content['qa_captcha_count']; // work around fact that reCAPTCHA can only display per page
if ($count>1) if ($count>1)
$html='[captcha placeholder]'; // single captcha will be moved about the page, to replace this $html='[captcha placeholder]'; // single captcha will be moved about the page, to replace this
else { else {
$qa_content['script_var']['qa_captcha_in']='qa_captcha_div_1'; $qa_content['script_var']['qa_captcha_in']='qa_captcha_div_1';
$html=$captcha->form_html($qa_content, @$errors['captcha']); $html=$captcha->form_html($qa_content, @$errors['captcha']);
} }
$fields['captcha']=array( $fields['captcha']=array(
'type' => 'custom', 'type' => 'custom',
'label' => qa_lang_html('misc/captcha_label'), 'label' => qa_lang_html('misc/captcha_label'),
'html' => '<div id="qa_captcha_div_'.$count.'">'.$html.'</div>', 'html' => '<div id="qa_captcha_div_'.$count.'">'.$html.'</div>',
'error' => @array_key_exists('captcha', $errors) ? qa_lang_html('misc/captcha_error') : null, 'error' => @array_key_exists('captcha', $errors) ? qa_lang_html('misc/captcha_error') : null,
'note' => $note, 'note' => $note,
); );
return "if (qa_captcha_in!='qa_captcha_div_".$count."') { document.getElementById('qa_captcha_div_".$count."').innerHTML=document.getElementById(qa_captcha_in).innerHTML; document.getElementById(qa_captcha_in).innerHTML=''; qa_captcha_in='qa_captcha_div_".$count."'; }"; return "if (qa_captcha_in!='qa_captcha_div_".$count."') { document.getElementById('qa_captcha_div_".$count."').innerHTML=document.getElementById(qa_captcha_in).innerHTML; document.getElementById(qa_captcha_in).innerHTML=''; qa_captcha_in='qa_captcha_div_".$count."'; }";
} }
return ''; return '';
} }
function qa_captcha_validate_post(&$errors) function qa_captcha_validate_post(&$errors)
/* /*
Check if captcha is submitted correctly, and if not, set $errors['captcha'] to a descriptive string Check if captcha is submitted correctly, and if not, set $errors['captcha'] to a descriptive string
*/ */
{ {
if (qa_captcha_available()) { if (qa_captcha_available()) {
$captcha=qa_load_module('captcha', qa_opt('captcha_module')); $captcha=qa_load_module('captcha', qa_opt('captcha_module'));
if (!$captcha->validate_post($error)) { if (!$captcha->validate_post($error)) {
$errors['captcha']=$error; $errors['captcha']=$error;
return false; return false;
} }
} }
return true; return true;
} }
/* /*
Omit PHP closing tag to help avoid accidental output Omit PHP closing tag to help avoid accidental output
*/ */
\ No newline at end of file
<?php <?php
/* /*
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-include/qa-app-cookies.php File: qa-include/qa-app-cookies.php
Version: See define()s at top of qa-include/qa-base.php Version: See define()s at top of qa-include/qa-base.php
Description: User cookie management (application level) for tracking anonymous posts Description: User cookie management (application level) for tracking anonymous posts
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../'); header('Location: ../');
exit; exit;
} }
function qa_cookie_get() function qa_cookie_get()
/* /*
Return the user identification cookie sent by the browser for this page request, or null if none Return the user identification cookie sent by the browser for this page request, or null if none
*/ */
{ {
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); } if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
return isset($_COOKIE['qa_id']) ? qa_gpc_to_string($_COOKIE['qa_id']) : null; return isset($_COOKIE['qa_id']) ? qa_gpc_to_string($_COOKIE['qa_id']) : null;
} }
function qa_cookie_get_create() function qa_cookie_get_create()
/* /*
Return user identification cookie sent by browser if valid, or create a new one if not. Return user identification cookie sent by browser if valid, or create a new one if not.
Either way, extend for another year (this is used when an anonymous post is created) Either way, extend for another year (this is used when an anonymous post is created)
*/ */
{ {
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); } if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
require_once QA_INCLUDE_DIR.'qa-db-cookies.php'; require_once QA_INCLUDE_DIR.'qa-db-cookies.php';
$cookieid=qa_cookie_get(); $cookieid=qa_cookie_get();
if (isset($cookieid) && qa_db_cookie_exists($cookieid)) if (isset($cookieid) && qa_db_cookie_exists($cookieid))
; // cookie is valid ; // cookie is valid
else else
$cookieid=qa_db_cookie_create(qa_remote_ip_address()); $cookieid=qa_db_cookie_create(qa_remote_ip_address());
setcookie('qa_id', $cookieid, time()+86400*365, '/', QA_COOKIE_DOMAIN); setcookie('qa_id', $cookieid, time()+86400*365, '/', QA_COOKIE_DOMAIN);
$_COOKIE['qa_id']=$cookieid; $_COOKIE['qa_id']=$cookieid;
return $cookieid; return $cookieid;
} }
function qa_cookie_report_action($cookieid, $action) function qa_cookie_report_action($cookieid, $action)
/* /*
Called after a database write $action performed by a user identified by $cookieid, Called after a database write $action performed by a user identified by $cookieid,
relating to $questionid, $answerid and/or $commentid relating to $questionid, $answerid and/or $commentid
*/ */
{ {
require_once QA_INCLUDE_DIR.'qa-db-cookies.php'; require_once QA_INCLUDE_DIR.'qa-db-cookies.php';
qa_db_cookie_written($cookieid, qa_remote_ip_address()); qa_db_cookie_written($cookieid, qa_remote_ip_address());
} }
/* /*
Omit PHP closing tag to help avoid accidental output Omit PHP closing tag to help avoid accidental output
*/ */
\ No newline at end of file
<?php <?php
/* /*
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-include/qa-app-emails.php File: qa-include/qa-app-emails.php
Version: See define()s at top of qa-include/qa-base.php Version: See define()s at top of qa-include/qa-base.php
Description: Wrapper functions for sending email notifications to users Description: Wrapper functions for sending email notifications to users
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../'); header('Location: ../');
exit; exit;
} }
require_once QA_INCLUDE_DIR.'qa-app-options.php'; require_once QA_INCLUDE_DIR.'qa-app-options.php';
function qa_suspend_notifications($suspend=true) function qa_suspend_notifications($suspend=true)
/* /*
Suspend the sending of all email notifications via qa_send_notification(...) if $suspend is true, otherwise Suspend the sending of all email notifications via qa_send_notification(...) if $suspend is true, otherwise
reinstate it. A counter is kept to allow multiple calls. reinstate it. A counter is kept to allow multiple calls.
*/ */
{ {
global $qa_notifications_suspended; global $qa_notifications_suspended;
$qa_notifications_suspended+=($suspend ? 1 : -1); $qa_notifications_suspended+=($suspend ? 1 : -1);
} }
function qa_send_notification($userid, $email, $handle, $subject, $body, $subs, $html = false) function qa_send_notification($userid, $email, $handle, $subject, $body, $subs, $html = false)
/* /*
Send email to person with $userid and/or $email and/or $handle (null/invalid values are ignored or retrieved from Send email to person with $userid and/or $email and/or $handle (null/invalid values are ignored or retrieved from
user database as appropriate). Email uses $subject and $body, after substituting each key in $subs with its user database as appropriate). Email uses $subject and $body, after substituting each key in $subs with its
corresponding value, plus applying some standard substitutions such as ^site_title, ^handle and ^email. corresponding value, plus applying some standard substitutions such as ^site_title, ^handle and ^email.
*/ */
{ {
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); } if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
global $qa_notifications_suspended; global $qa_notifications_suspended;
if ($qa_notifications_suspended>0) if ($qa_notifications_suspended>0)
return false; return false;
require_once QA_INCLUDE_DIR.'qa-db-selects.php'; require_once QA_INCLUDE_DIR.'qa-db-selects.php';
require_once QA_INCLUDE_DIR.'qa-util-string.php'; require_once QA_INCLUDE_DIR.'qa-util-string.php';
if (isset($userid)) { if (isset($userid)) {
$needemail=!qa_email_validate(@$email); // take from user if invalid, e.g. @ used in practice $needemail=!qa_email_validate(@$email); // take from user if invalid, e.g. @ used in practice
$needhandle=empty($handle); $needhandle=empty($handle);
if ($needemail || $needhandle) { if ($needemail || $needhandle) {
if (QA_FINAL_EXTERNAL_USERS) { if (QA_FINAL_EXTERNAL_USERS) {
if ($needhandle) { if ($needhandle) {
$handles=qa_get_public_from_userids(array($userid)); $handles=qa_get_public_from_userids(array($userid));
$handle=@$handles[$userid]; $handle=@$handles[$userid];
} }
if ($needemail) if ($needemail)
$email=qa_get_user_email($userid); $email=qa_get_user_email($userid);
} else { } else {
$useraccount=qa_db_select_with_pending( $useraccount=qa_db_select_with_pending(
array( array(
'columns' => array('email', 'handle'), 'columns' => array('email', 'handle'),
'source' => '^users WHERE userid = #', 'source' => '^users WHERE userid = #',
'arguments' => array($userid), 'arguments' => array($userid),
'single' => true, 'single' => true,
) )
); );
if ($needhandle) if ($needhandle)
$handle=@$useraccount['handle']; $handle=@$useraccount['handle'];
if ($needemail) if ($needemail)
$email=@$useraccount['email']; $email=@$useraccount['email'];
} }
} }
} }
if (isset($email) && qa_email_validate($email)) { if (isset($email) && qa_email_validate($email)) {
$subs['^site_title']=qa_opt('site_title'); $subs['^site_title']=qa_opt('site_title');
$subs['^handle']=$handle; $subs['^handle']=$handle;
$subs['^email']=$email; $subs['^email']=$email;
$subs['^open']="\n"; $subs['^open']="\n";
$subs['^close']="\n"; $subs['^close']="\n";
return qa_send_email(array( return qa_send_email(array(
'fromemail' => qa_opt('from_email'), 'fromemail' => qa_opt('from_email'),
'fromname' => qa_opt('site_title'), 'fromname' => qa_opt('site_title'),
'toemail' => $email, 'toemail' => $email,
'toname' => $handle, 'toname' => $handle,
'subject' => strtr($subject, $subs), 'subject' => strtr($subject, $subs),
'body' => (empty($handle) ? '' : qa_lang_sub('emails/to_handle_prefix', $handle)).strtr($body, $subs), 'body' => (empty($handle) ? '' : qa_lang_sub('emails/to_handle_prefix', $handle)).strtr($body, $subs),
'html' => $html, 'html' => $html,
)); ));
} else } else
return false; return false;
} }
function qa_send_email($params) function qa_send_email($params)
/* /*
Send the email based on the $params array - the following keys are required (some can be empty): fromemail, Send the email based on the $params array - the following keys are required (some can be empty): fromemail,
fromname, toemail, toname, subject, body, html fromname, toemail, toname, subject, body, html
*/ */
{ {
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); } if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
// @error_log(print_r($params, true)); // @error_log(print_r($params, true));
require_once QA_INCLUDE_DIR.'vendor/PHPMailer/PHPMailerAutoload.php'; require_once QA_INCLUDE_DIR.'vendor/PHPMailer/PHPMailerAutoload.php';
$mailer=new PHPMailer(); $mailer=new PHPMailer();
$mailer->CharSet='utf-8'; $mailer->CharSet='utf-8';
$mailer->From=$params['fromemail']; $mailer->From=$params['fromemail'];
$mailer->Sender=$params['fromemail']; $mailer->Sender=$params['fromemail'];
$mailer->FromName=$params['fromname']; $mailer->FromName=$params['fromname'];
$mailer->AddAddress($params['toemail'], $params['toname']); $mailer->AddAddress($params['toemail'], $params['toname']);
$mailer->Subject=$params['subject']; $mailer->Subject=$params['subject'];
$mailer->Body=$params['body']; $mailer->Body=$params['body'];
if ($params['html']) if ($params['html'])
$mailer->IsHTML(true); $mailer->IsHTML(true);
if (qa_opt('smtp_active')) { if (qa_opt('smtp_active')) {
$mailer->IsSMTP(); $mailer->IsSMTP();
$mailer->Host=qa_opt('smtp_address'); $mailer->Host=qa_opt('smtp_address');
$mailer->Port=qa_opt('smtp_port'); $mailer->Port=qa_opt('smtp_port');
if (qa_opt('smtp_secure')) if (qa_opt('smtp_secure'))
$mailer->SMTPSecure=qa_opt('smtp_secure'); $mailer->SMTPSecure=qa_opt('smtp_secure');
if (qa_opt('smtp_authenticate')) { if (qa_opt('smtp_authenticate')) {
$mailer->SMTPAuth=true; $mailer->SMTPAuth=true;
$mailer->Username=qa_opt('smtp_username'); $mailer->Username=qa_opt('smtp_username');
$mailer->Password=qa_opt('smtp_password'); $mailer->Password=qa_opt('smtp_password');
} }
} }
return $mailer->Send(); return $mailer->Send();
} }
/* /*
Omit PHP closing tag to help avoid accidental output Omit PHP closing tag to help avoid accidental output
*/ */
<?php <?php
/* /*
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-include/qa-app-events.php File: qa-include/qa-app-events.php
Version: See define()s at top of qa-include/qa-base.php Version: See define()s at top of qa-include/qa-base.php
Description: Handles the submission of events to the database (application level) Description: Handles the submission of events to the database (application level)
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../'); header('Location: ../');
exit; exit;
} }
require_once QA_INCLUDE_DIR.'qa-db-events.php'; require_once QA_INCLUDE_DIR.'qa-db-events.php';
require_once QA_INCLUDE_DIR.'qa-app-updates.php'; require_once QA_INCLUDE_DIR.'qa-app-updates.php';
function qa_create_event_for_q_user($questionid, $lastpostid, $updatetype, $lastuserid, $otheruserid=null, $timestamp=null) function qa_create_event_for_q_user($questionid, $lastpostid, $updatetype, $lastuserid, $otheruserid=null, $timestamp=null)
/* /*
Add appropriate events to the database for an action performed on a question. The event of type $updatetype relates Add appropriate events to the database for an action performed on a question. The event of type $updatetype relates
to $lastpostid whose antecedent question is $questionid, and was caused by $lastuserid. Pass a unix $timestamp for to $lastpostid whose antecedent question is $questionid, and was caused by $lastuserid. Pass a unix $timestamp for
the event time or leave as null to use now. This will add an event to $questionid's and $lastuserid's streams. If the event time or leave as null to use now. This will add an event to $questionid's and $lastuserid's streams. If
$otheruserid is set, it will also add an notification-style event for that user, unless they are the one who did it. $otheruserid is set, it will also add an notification-style event for that user, unless they are the one who did it.
*/ */
{ {
qa_db_event_create_for_entity(QA_ENTITY_QUESTION, $questionid, $questionid, $lastpostid, $updatetype, $lastuserid, $timestamp); // anyone who favorited the question qa_db_event_create_for_entity(QA_ENTITY_QUESTION, $questionid, $questionid, $lastpostid, $updatetype, $lastuserid, $timestamp); // anyone who favorited the question
if (isset($lastuserid) && !QA_FINAL_EXTERNAL_USERS) if (isset($lastuserid) && !QA_FINAL_EXTERNAL_USERS)
qa_db_event_create_for_entity(QA_ENTITY_USER, $lastuserid, $questionid, $lastpostid, $updatetype, $lastuserid, $timestamp); // anyone who favorited the user who did it qa_db_event_create_for_entity(QA_ENTITY_USER, $lastuserid, $questionid, $lastpostid, $updatetype, $lastuserid, $timestamp); // anyone who favorited the user who did it
if (isset($otheruserid) && ($otheruserid!=$lastuserid)) if (isset($otheruserid) && ($otheruserid!=$lastuserid))
qa_db_event_create_not_entity($otheruserid, $questionid, $lastpostid, $updatetype, $lastuserid, $timestamp); // possible other user to be informed qa_db_event_create_not_entity($otheruserid, $questionid, $lastpostid, $updatetype, $lastuserid, $timestamp); // possible other user to be informed
} }
function qa_create_event_for_tags($tagstring, $questionid, $updatetype, $lastuserid, $timestamp=null) function qa_create_event_for_tags($tagstring, $questionid, $updatetype, $lastuserid, $timestamp=null)
/* /*
Add appropriate events to the database for an action performed on a set of tags in $tagstring (namely, a question Add appropriate events to the database for an action performed on a set of tags in $tagstring (namely, a question
being created with those tags or having one of those tags added afterwards). The event of type $updatetype relates being created with those tags or having one of those tags added afterwards). The event of type $updatetype relates
to the question $questionid, and was caused by $lastuserid. Pass a unix $timestamp for the event time or leave as to the question $questionid, and was caused by $lastuserid. Pass a unix $timestamp for the event time or leave as
null to use now. null to use now.
*/ */
{ {
require_once QA_INCLUDE_DIR.'qa-util-string.php'; require_once QA_INCLUDE_DIR.'qa-util-string.php';
require_once QA_INCLUDE_DIR.'qa-db-post-create.php'; require_once QA_INCLUDE_DIR.'qa-db-post-create.php';
$tagwordids=qa_db_word_mapto_ids(array_unique(qa_tagstring_to_tags($tagstring))); $tagwordids=qa_db_word_mapto_ids(array_unique(qa_tagstring_to_tags($tagstring)));
foreach ($tagwordids as $wordid) foreach ($tagwordids as $wordid)
qa_db_event_create_for_entity(QA_ENTITY_TAG, $wordid, $questionid, $questionid, $updatetype, $lastuserid, $timestamp); qa_db_event_create_for_entity(QA_ENTITY_TAG, $wordid, $questionid, $questionid, $updatetype, $lastuserid, $timestamp);
} }
function qa_create_event_for_category($categoryid, $questionid, $updatetype, $lastuserid, $timestamp=null) function qa_create_event_for_category($categoryid, $questionid, $updatetype, $lastuserid, $timestamp=null)
/* /*
Add appropriate events to the database for an action performed on $categoryid (namely, a question being created in Add appropriate events to the database for an action performed on $categoryid (namely, a question being created in
that category or being moved to it later on), along with all of its ancestor categories. The event of type that category or being moved to it later on), along with all of its ancestor categories. The event of type
$updatetype relates to the question $questionid, and was caused by $lastuserid. Pass a unix $timestamp for the event $updatetype relates to the question $questionid, and was caused by $lastuserid. Pass a unix $timestamp for the event
time or leave as null to use now. time or leave as null to use now.
*/ */
{ {
if (isset($categoryid)) { if (isset($categoryid)) {
require_once QA_INCLUDE_DIR.'qa-db-selects.php'; require_once QA_INCLUDE_DIR.'qa-db-selects.php';
require_once QA_INCLUDE_DIR.'qa-app-format.php'; require_once QA_INCLUDE_DIR.'qa-app-format.php';
$categories=qa_category_path(qa_db_single_select(qa_db_category_nav_selectspec($categoryid, true)), $categoryid); $categories=qa_category_path(qa_db_single_select(qa_db_category_nav_selectspec($categoryid, true)), $categoryid);
foreach ($categories as $category) foreach ($categories as $category)
qa_db_event_create_for_entity(QA_ENTITY_CATEGORY, $category['categoryid'], $questionid, $questionid, $updatetype, $lastuserid, $timestamp); qa_db_event_create_for_entity(QA_ENTITY_CATEGORY, $category['categoryid'], $questionid, $questionid, $updatetype, $lastuserid, $timestamp);
} }
} }
/* /*
Omit PHP closing tag to help avoid accidental output Omit PHP closing tag to help avoid accidental output
*/ */
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
<?php <?php
/* /*
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-include/qa-app-mailing.php File: qa-include/qa-app-mailing.php
Version: See define()s at top of qa-include/qa-base.php Version: See define()s at top of qa-include/qa-base.php
Description: Functions for sending a mailing to all users Description: Functions for sending a mailing to all users
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../'); header('Location: ../');
exit; exit;
} }
function qa_mailing_start() function qa_mailing_start()
/* /*
Start a mailing to all users, unless one has already been started Start a mailing to all users, unless one has already been started
*/ */
{ {
require_once QA_INCLUDE_DIR.'qa-db-admin.php'; require_once QA_INCLUDE_DIR.'qa-db-admin.php';
if (strlen(qa_opt('mailing_last_userid'))==0) { if (strlen(qa_opt('mailing_last_userid'))==0) {
qa_opt('mailing_last_timestamp', time()); qa_opt('mailing_last_timestamp', time());
qa_opt('mailing_last_userid', '0'); qa_opt('mailing_last_userid', '0');
qa_opt('mailing_total_users', qa_db_count_users()); qa_opt('mailing_total_users', qa_db_count_users());
qa_opt('mailing_done_users', 0); qa_opt('mailing_done_users', 0);
} }
} }
function qa_mailing_stop() function qa_mailing_stop()
/* /*
Stop a mailing to all users Stop a mailing to all users
*/ */
{ {
qa_opt('mailing_last_timestamp', ''); qa_opt('mailing_last_timestamp', '');
qa_opt('mailing_last_userid', ''); qa_opt('mailing_last_userid', '');
qa_opt('mailing_done_users', ''); qa_opt('mailing_done_users', '');
qa_opt('mailing_total_users', ''); qa_opt('mailing_total_users', '');
} }
function qa_mailing_perform_step() function qa_mailing_perform_step()
/* /*
Allow the mailing to proceed forwards, for the appropriate amount of time and users, based on the options Allow the mailing to proceed forwards, for the appropriate amount of time and users, based on the options
*/ */
{ {
require_once QA_INCLUDE_DIR.'qa-db-users.php'; require_once QA_INCLUDE_DIR.'qa-db-users.php';
$lastuserid=qa_opt('mailing_last_userid'); $lastuserid=qa_opt('mailing_last_userid');
if (strlen($lastuserid)) { if (strlen($lastuserid)) {
$thistime=time(); $thistime=time();
$lasttime=qa_opt('mailing_last_timestamp'); $lasttime=qa_opt('mailing_last_timestamp');
$perminute=qa_opt('mailing_per_minute'); $perminute=qa_opt('mailing_per_minute');
if (($lasttime-$thistime)>60) // if it's been a while, we assume there hasn't been continuous mailing... if (($lasttime-$thistime)>60) // if it's been a while, we assume there hasn't been continuous mailing...
$lasttime=$thistime-1; // ... so only do 1 second's worth $lasttime=$thistime-1; // ... so only do 1 second's worth
else // otherwise... else // otherwise...
$lasttime=max($lasttime, $thistime-6); // ... don't do more than 6 seconds' worth $lasttime=max($lasttime, $thistime-6); // ... don't do more than 6 seconds' worth
$count=min(floor(($thistime-$lasttime)*$perminute/60), 100); // don't do more than 100 messages at a time $count=min(floor(($thistime-$lasttime)*$perminute/60), 100); // don't do more than 100 messages at a time
if ($count>0) { if ($count>0) {
qa_opt('mailing_last_timestamp', $thistime+30); qa_opt('mailing_last_timestamp', $thistime+30);
// prevents a parallel call to qa_mailing_perform_step() from sending messages, unless we're very unlucky with timing (poor man's mutex) // prevents a parallel call to qa_mailing_perform_step() from sending messages, unless we're very unlucky with timing (poor man's mutex)
$sentusers=0; $sentusers=0;
$users=qa_db_users_get_mailing_next($lastuserid, $count); $users=qa_db_users_get_mailing_next($lastuserid, $count);
if (count($users)) { if (count($users)) {
foreach ($users as $user) foreach ($users as $user)
$lastuserid=max($lastuserid, $user['userid']); $lastuserid=max($lastuserid, $user['userid']);
qa_opt('mailing_last_userid', $lastuserid); qa_opt('mailing_last_userid', $lastuserid);
qa_opt('mailing_done_users', qa_opt('mailing_done_users')+count($users)); qa_opt('mailing_done_users', qa_opt('mailing_done_users')+count($users));
foreach ($users as $user) foreach ($users as $user)
if (!($user['flags'] & QA_USER_FLAGS_NO_MAILINGS)) { if (!($user['flags'] & QA_USER_FLAGS_NO_MAILINGS)) {
qa_mailing_send_one($user['userid'], $user['handle'], $user['email'], $user['emailcode']); qa_mailing_send_one($user['userid'], $user['handle'], $user['email'], $user['emailcode']);
$sentusers++; $sentusers++;
} }
qa_opt('mailing_last_timestamp', $lasttime+$sentusers*60/$perminute); // can be floating point result, based on number of mails actually sent qa_opt('mailing_last_timestamp', $lasttime+$sentusers*60/$perminute); // can be floating point result, based on number of mails actually sent
} else } else
qa_mailing_stop(); qa_mailing_stop();
} }
} }
} }
function qa_mailing_send_one($userid, $handle, $email, $emailcode) function qa_mailing_send_one($userid, $handle, $email, $emailcode)
/* /*
Send a single message from the mailing, to $userid with $handle and $email. Send a single message from the mailing, to $userid with $handle and $email.
Pass the user's existing $emailcode if there is one, otherwise a new one will be set up Pass the user's existing $emailcode if there is one, otherwise a new one will be set up
*/ */
{ {
require_once QA_INCLUDE_DIR.'qa-app-emails.php'; require_once QA_INCLUDE_DIR.'qa-app-emails.php';
require_once QA_INCLUDE_DIR.'qa-db-users.php'; require_once QA_INCLUDE_DIR.'qa-db-users.php';
if (!strlen(trim($emailcode))) { if (!strlen(trim($emailcode))) {
$emailcode=qa_db_user_rand_emailcode(); $emailcode=qa_db_user_rand_emailcode();
qa_db_user_set($userid, 'emailcode', $emailcode); qa_db_user_set($userid, 'emailcode', $emailcode);
} }
$unsubscribeurl=qa_path_absolute('unsubscribe', array('c' => $emailcode, 'u' => $handle)); $unsubscribeurl=qa_path_absolute('unsubscribe', array('c' => $emailcode, 'u' => $handle));
return qa_send_email(array( return qa_send_email(array(
'fromemail' => qa_opt('mailing_from_email'), 'fromemail' => qa_opt('mailing_from_email'),
'fromname' => qa_opt('mailing_from_name'), 'fromname' => qa_opt('mailing_from_name'),
'toemail' => $email, 'toemail' => $email,
'toname' => $handle, 'toname' => $handle,
'subject' => qa_opt('mailing_subject'), 'subject' => qa_opt('mailing_subject'),
'body' => trim(qa_opt('mailing_body'))."\n\n\n".qa_lang('users/unsubscribe').' '.$unsubscribeurl, 'body' => trim(qa_opt('mailing_body'))."\n\n\n".qa_lang('users/unsubscribe').' '.$unsubscribeurl,
'html' => false, 'html' => false,
)); ));
} }
function qa_mailing_progress_message() function qa_mailing_progress_message()
/* /*
Return a message describing current progress in the mailing Return a message describing current progress in the mailing
*/ */
{ {
if (strlen(qa_opt('mailing_last_userid'))) if (strlen(qa_opt('mailing_last_userid')))
return strtr(qa_lang('admin/mailing_progress'), array( return strtr(qa_lang('admin/mailing_progress'), array(
'^1' => number_format(qa_opt('mailing_done_users')), '^1' => number_format(qa_opt('mailing_done_users')),
'^2' => number_format(qa_opt('mailing_total_users')), '^2' => number_format(qa_opt('mailing_total_users')),
)); ));
else else
return null; return null;
} }
/* /*
Omit PHP closing tag to help avoid accidental output Omit PHP closing tag to help avoid accidental output
*/ */
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment