Commit 54ada742 by Scott

Coding style (app/)

parent f24542bb
......@@ -20,82 +20,103 @@
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: ../');
exit;
}
}
function qa_get_blob_url($blobid, $absolute=false)
/*
Return the URL which will output $blobid from the database when requested, $absolute or relative
*/
{
/**
* Return the URL which will output $blobid from the database when requested, $absolute or relative
* @param $blobid
* @param bool $absolute
* @return mixed|string
*/
function qa_get_blob_url($blobid, $absolute = false)
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
return qa_path('blob', array('qa_blobid' => $blobid), $absolute ? qa_opt('site_url') : null, QA_URL_FORMAT_PARAMS);
}
}
function qa_get_blob_directory($blobid)
/*
Return the full path to the on-disk directory for blob $blobid (subdirectories are named by the first 3 digits of $blobid)
*/
{
/**
* Return the full path to the on-disk directory for blob $blobid (subdirectories are named by the first 3 digits of $blobid)
* @param $blobid
* @return mixed|string
*/
function qa_get_blob_directory($blobid)
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
return rtrim(QA_BLOBS_DIRECTORY, '/').'/'.substr(str_pad($blobid, 20, '0', STR_PAD_LEFT), 0, 3);
}
return rtrim(QA_BLOBS_DIRECTORY, '/') . '/' . substr(str_pad($blobid, 20, '0', STR_PAD_LEFT), 0, 3);
}
function qa_get_blob_filename($blobid, $format)
/*
Return the full page and filename of blob $blobid which is in $format ($format is used as the file name suffix e.g. .jpg)
*/
{
/**
* Return the full page and filename of blob $blobid which is in $format ($format is used as the file name suffix e.g. .jpg)
* @param $blobid
* @param $format
* @return mixed|string
*/
function qa_get_blob_filename($blobid, $format)
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
return qa_get_blob_directory($blobid).'/'.$blobid.'.'.preg_replace('/[^A-Za-z0-9]/', '', $format);
}
function qa_create_blob($content, $format, $sourcefilename=null, $userid=null, $cookieid=null, $ip=null)
/*
Create a new blob (storing the content in the database or on disk as appropriate) with $content and $format, returning its blobid.
Pass the original name of the file uploaded in $sourcefilename and the $userid, $cookieid and $ip of the user creating it
*/
{
return qa_get_blob_directory($blobid) . '/' . $blobid . '.' . preg_replace('/[^A-Za-z0-9]/', '', $format);
}
/**
* Create a new blob (storing the content in the database or on disk as appropriate) with $content and $format, returning its blobid.
* Pass the original name of the file uploaded in $sourcefilename and the $userid, $cookieid and $ip of the user creating it
* @param $content
* @param $format
* @param $sourcefilename
* @param $userid
* @param $cookieid
* @param $ip
* @return mixed|null|string
*/
function qa_create_blob($content, $format, $sourcefilename = null, $userid = null, $cookieid = null, $ip = null)
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
require_once QA_INCLUDE_DIR.'db/blobs.php';
require_once QA_INCLUDE_DIR . 'db/blobs.php';
$blobid=qa_db_blob_create(defined('QA_BLOBS_DIRECTORY') ? null : $content, $format, $sourcefilename, $userid, $cookieid, $ip);
$blobid = qa_db_blob_create(defined('QA_BLOBS_DIRECTORY') ? null : $content, $format, $sourcefilename, $userid, $cookieid, $ip);
if (isset($blobid) && defined('QA_BLOBS_DIRECTORY'))
if (isset($blobid) && defined('QA_BLOBS_DIRECTORY')) {
// still write content to the database if writing to disk failed
if (!qa_write_blob_file($blobid, $content, $format))
qa_db_blob_set_content($blobid, $content); // still write content to the database if writing to disk failed
return $blobid;
qa_db_blob_set_content($blobid, $content);
}
function qa_write_blob_file($blobid, $content, $format)
/*
Write the on-disk file for blob $blobid with $content and $format. Returns true if the write succeeded, false otherwise.
*/
{
return $blobid;
}
/**
* Write the on-disk file for blob $blobid with $content and $format. Returns true if the write succeeded, false otherwise.
* @param $blobid
* @param $content
* @param $format
* @return bool|mixed
*/
function qa_write_blob_file($blobid, $content, $format)
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
$written=false;
$written = false;
$directory=qa_get_blob_directory($blobid);
$directory = qa_get_blob_directory($blobid);
if (is_dir($directory) || mkdir($directory, fileperms(rtrim(QA_BLOBS_DIRECTORY, '/')) & 0777)) {
$filename=qa_get_blob_filename($blobid, $format);
$filename = qa_get_blob_filename($blobid, $format);
$file=fopen($filename, 'xb');
$file = fopen($filename, 'xb');
if (is_resource($file)) {
if (fwrite($file, $content)>=strlen($content))
$written=true;
if (fwrite($file, $content) >= strlen($content))
$written = true;
fclose($file);
......@@ -105,32 +126,37 @@
}
return $written;
}
}
function qa_read_blob($blobid)
/*
Retrieve blob $blobid from the database, reading the content from disk if appropriate
*/
{
/**
* Retrieve blob $blobid from the database, reading the content from disk if appropriate
* @param $blobid
* @return array|mixed|null
*/
function qa_read_blob($blobid)
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
require_once QA_INCLUDE_DIR.'db/blobs.php';
require_once QA_INCLUDE_DIR . 'db/blobs.php';
$blob=qa_db_blob_read($blobid);
$blob = qa_db_blob_read($blobid);
if (isset($blob) && defined('QA_BLOBS_DIRECTORY') && !isset($blob['content']))
$blob['content']=qa_read_blob_file($blobid, $blob['format']);
$blob['content'] = qa_read_blob_file($blobid, $blob['format']);
return $blob;
}
}
function qa_read_blob_file($blobid, $format)
/*
Read the content of blob $blobid in $format from disk. On failure, it will return false.
*/
{
/**
* Read the content of blob $blobid in $format from disk. On failure, it will return false.
* @param $blobid
* @param $format
* @return mixed|null|string
*/
function qa_read_blob_file($blobid, $format)
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
$filename = qa_get_blob_filename($blobid, $format);
......@@ -138,53 +164,55 @@
return file_get_contents($filename);
else
return null;
}
}
function qa_delete_blob($blobid)
/*
Delete blob $blobid from the database, and remove the on-disk file if appropriate
*/
{
/**
* Delete blob $blobid from the database, and remove the on-disk file if appropriate
* @param $blobid
* @return mixed
*/
function qa_delete_blob($blobid)
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
require_once QA_INCLUDE_DIR.'db/blobs.php';
require_once QA_INCLUDE_DIR . 'db/blobs.php';
if (defined('QA_BLOBS_DIRECTORY')) {
$blob=qa_db_blob_read($blobid);
$blob = qa_db_blob_read($blobid);
if (isset($blob) && !isset($blob['content']))
unlink(qa_get_blob_filename($blobid, $blob['format']));
}
qa_db_blob_delete($blobid);
}
}
function qa_delete_blob_file($blobid, $format)
/*
Delete the on-disk file for blob $blobid in $format
*/
{
/**
* Delete the on-disk file for blob $blobid in $format
* @param $blobid
* @param $format
* @return mixed
*/
function qa_delete_blob_file($blobid, $format)
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
unlink(qa_get_blob_filename($blobid, $format));
}
}
function qa_blob_exists($blobid)
/*
Check if blob $blobid exists
*/
{
/**
* Check if blob $blobid exists
* @param $blobid
* @return bool|mixed
*/
function qa_blob_exists($blobid)
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
require_once QA_INCLUDE_DIR.'db/blobs.php';
require_once QA_INCLUDE_DIR . 'db/blobs.php';
return qa_db_blob_exists($blobid);
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
}
......@@ -39,6 +39,8 @@ function qa_captcha_available()
/**
* Return an HTML string explaining $captchareason (from qa_user_captcha_reason()) to the user about why they are seeing a captcha
* @param $captchareason
* @return mixed|null|string
*/
function qa_captcha_reason_note($captchareason)
{
......@@ -65,8 +67,13 @@ function qa_captcha_reason_note($captchareason)
/**
* Prepare $qa_content for showing a captcha, adding the element to $fields, given previous $errors, and a $note to display.
* Returns JavaScript required to load CAPTCHA when field is shown by user (e.g. clicking comment button).
* @param $qa_content
* @param $fields
* @param $errors
* @param $note
* @return string
*/
function qa_set_up_captcha_field(&$qa_content, &$fields, $errors, $note=null)
function qa_set_up_captcha_field(&$qa_content, &$fields, $errors, $note = null)
{
if (!qa_captcha_available())
return '';
......@@ -79,8 +86,7 @@ function qa_set_up_captcha_field(&$qa_content, &$fields, $errors, $note=null)
if ($count > 1) {
// use blank captcha in order to load via JS
$html = '';
}
else {
} else {
// first captcha is always loaded explicitly
$qa_content['script_var']['qa_captcha_in'] = 'qa_captcha_div_1';
$html = $captcha->form_html($qa_content, @$errors['captcha']);
......@@ -89,17 +95,19 @@ function qa_set_up_captcha_field(&$qa_content, &$fields, $errors, $note=null)
$fields['captcha'] = array(
'type' => 'custom',
'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,
'note' => $note,
);
return "if (!document.getElementById('qa_captcha_div_".$count."').hasChildNodes()) { recaptcha_load('qa_captcha_div_".$count."'); }";
return "if (!document.getElementById('qa_captcha_div_" . $count . "').hasChildNodes()) { recaptcha_load('qa_captcha_div_" . $count . "'); }";
}
/**
* Check if captcha is submitted correctly, and if not, set $errors['captcha'] to a descriptive string.
* @param $errors
* @return bool
*/
function qa_captcha_validate_post(&$errors)
{
......
......@@ -20,59 +20,56 @@
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: ../');
exit;
}
}
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
*/
function qa_cookie_get()
{
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;
}
}
function qa_cookie_get_create()
/*
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)
*/
{
/**
* 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)
*/
function qa_cookie_get_create()
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
require_once QA_INCLUDE_DIR.'db/cookies.php';
require_once QA_INCLUDE_DIR . 'db/cookies.php';
$cookieid=qa_cookie_get();
$cookieid = qa_cookie_get();
if (isset($cookieid) && qa_db_cookie_exists($cookieid))
; // cookie is valid
else
$cookieid=qa_db_cookie_create(qa_remote_ip_address());
if (!isset($cookieid) || !qa_db_cookie_exists($cookieid)) {
// cookie is invalid
$cookieid = qa_db_cookie_create(qa_remote_ip_address());
}
setcookie('qa_id', $cookieid, time()+86400*365, '/', QA_COOKIE_DOMAIN, (bool)ini_get('session.cookie_secure'), true);
$_COOKIE['qa_id']=$cookieid;
setcookie('qa_id', $cookieid, time() + 86400 * 365, '/', QA_COOKIE_DOMAIN, (bool)ini_get('session.cookie_secure'), true);
$_COOKIE['qa_id'] = $cookieid;
return $cookieid;
}
}
function qa_cookie_report_action($cookieid, $action)
/*
Called after a database write $action performed by a user identified by $cookieid,
relating to $questionid, $answerid and/or $commentid
*/
{
require_once QA_INCLUDE_DIR.'db/cookies.php';
/**
* Called after a database write $action performed by a user identified by $cookieid,
* relating to $questionid, $answerid and/or $commentid
* @param $cookieid
* @param $action
*/
function qa_cookie_report_action($cookieid, $action)
{
require_once QA_INCLUDE_DIR . 'db/cookies.php';
qa_db_cookie_written($cookieid, qa_remote_ip_address());
}
/*
Omit PHP closing tag to help avoid accidental output
*/
}
......@@ -20,59 +20,68 @@
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: ../');
exit;
}
}
require_once QA_INCLUDE_DIR.'app/options.php';
require_once QA_INCLUDE_DIR . 'app/options.php';
function qa_suspend_notifications($suspend=true)
/*
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.
*/
{
/**
* 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.
* @param bool $suspend
*/
function qa_suspend_notifications($suspend = true)
{
global $qa_notifications_suspended;
$qa_notifications_suspended+=($suspend ? 1 : -1);
}
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
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.
*/
{
$qa_notifications_suspended += ($suspend ? 1 : -1);
}
/**
* 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
* corresponding value, plus applying some standard substitutions such as ^site_title, ^handle and ^email.
* @param $userid
* @param $email
* @param $handle
* @param $subject
* @param $body
* @param $subs
* @param bool $html
* @return bool
*/
function qa_send_notification($userid, $email, $handle, $subject, $body, $subs, $html = false)
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
global $qa_notifications_suspended;
if ($qa_notifications_suspended>0)
if ($qa_notifications_suspended > 0)
return false;
require_once QA_INCLUDE_DIR.'db/selects.php';
require_once QA_INCLUDE_DIR.'util/string.php';
require_once QA_INCLUDE_DIR . 'db/selects.php';
require_once QA_INCLUDE_DIR . 'util/string.php';
if (isset($userid)) {
$needemail=!qa_email_validate(@$email); // take from user if invalid, e.g. @ used in practice
$needhandle=empty($handle);
$needemail = !qa_email_validate(@$email); // take from user if invalid, e.g. @ used in practice
$needhandle = empty($handle);
if ($needemail || $needhandle) {
if (QA_FINAL_EXTERNAL_USERS) {
if ($needhandle) {
$handles=qa_get_public_from_userids(array($userid));
$handle=@$handles[$userid];
$handles = qa_get_public_from_userids(array($userid));
$handle = @$handles[$userid];
}
if ($needemail)
$email=qa_get_user_email($userid);
$email = qa_get_user_email($userid);
} else {
$useraccount=qa_db_select_with_pending(
$useraccount = qa_db_select_with_pending(
array(
'columns' => array('email', 'handle'),
'source' => '^users WHERE userid = #',
......@@ -82,20 +91,20 @@
);
if ($needhandle)
$handle=@$useraccount['handle'];
$handle = @$useraccount['handle'];
if ($needemail)
$email=@$useraccount['email'];
$email = @$useraccount['email'];
}
}
}
if (isset($email) && qa_email_validate($email)) {
$subs['^site_title']=qa_opt('site_title');
$subs['^handle']=$handle;
$subs['^email']=$email;
$subs['^open']="\n";
$subs['^close']="\n";
$subs['^site_title'] = qa_opt('site_title');
$subs['^handle'] = $handle;
$subs['^email'] = $email;
$subs['^open'] = "\n";
$subs['^close'] = "\n";
return qa_send_email(array(
'fromemail' => qa_opt('from_email'),
......@@ -103,76 +112,72 @@
'toemail' => $email,
'toname' => $handle,
'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,
));
}
} else
return false;
}
}
function qa_send_email($params)
/*
Send the email based on the $params array - the following keys are required (some can be empty): fromemail,
fromname, toemail, toname, subject, body, html
*/
{
/**
* Send the email based on the $params array - the following keys are required (some can be empty): fromemail,
* fromname, toemail, toname, subject, body, html
* @param $params
* @return bool
*/
function qa_send_email($params)
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
// @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->CharSet='utf-8';
$mailer = new PHPMailer();
$mailer->CharSet = 'utf-8';
$mailer->From=$params['fromemail'];
$mailer->Sender=$params['fromemail'];
$mailer->FromName=$params['fromname'];
$mailer->From = $params['fromemail'];
$mailer->Sender = $params['fromemail'];
$mailer->FromName = $params['fromname'];
$mailer->addAddress($params['toemail'], $params['toname']);
if(!empty($params['replytoemail'])){
if (!empty($params['replytoemail'])) {
$mailer->addReplyTo($params['replytoemail'], $params['replytoname']);
}
$mailer->Subject=$params['subject'];
$mailer->Body=$params['body'];
$mailer->Subject = $params['subject'];
$mailer->Body = $params['body'];
if ($params['html'])
$mailer->isHTML(true);
if (qa_opt('smtp_active')) {
$mailer->isSMTP();
$mailer->Host=qa_opt('smtp_address');
$mailer->Port=qa_opt('smtp_port');
$mailer->Host = qa_opt('smtp_address');
$mailer->Port = qa_opt('smtp_port');
if (qa_opt('smtp_secure')){
$mailer->SMTPSecure=qa_opt('smtp_secure');
}
else {
$mailer->SMTPOptions=array(
if (qa_opt('smtp_secure')) {
$mailer->SMTPSecure = qa_opt('smtp_secure');
} else {
$mailer->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
'allow_self_signed' => true,
),
);
}
if (qa_opt('smtp_authenticate')) {
$mailer->SMTPAuth=true;
$mailer->Username=qa_opt('smtp_username');
$mailer->Password=qa_opt('smtp_password');
$mailer->SMTPAuth = true;
$mailer->Username = qa_opt('smtp_username');
$mailer->Password = qa_opt('smtp_password');
}
}
$send_status = $mailer->send();
if(!$send_status){
@error_log('PHP Question2Answer email send error: '.$mailer->ErrorInfo);
if (!$send_status) {
@error_log('PHP Question2Answer email send error: ' . $mailer->ErrorInfo);
}
return $send_status;
}
/*
Omit PHP closing tag to help avoid accidental output
*/
}
......@@ -20,69 +20,82 @@
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: ../');
exit;
}
require_once QA_INCLUDE_DIR.'db/events.php';
require_once QA_INCLUDE_DIR.'app/updates.php';
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
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
$otheruserid is set, it will also add an notification-style event for that user, unless they are the one who did it.
*/
{
}
require_once QA_INCLUDE_DIR . 'db/events.php';
require_once QA_INCLUDE_DIR . 'app/updates.php';
/**
* 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
* 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.
* @param $questionid
* @param $lastpostid
* @param $updatetype
* @param $lastuserid
* @param $otheruserid
* @param $timestamp
*/
function qa_create_event_for_q_user($questionid, $lastpostid, $updatetype, $lastuserid, $otheruserid = null, $timestamp = null)
{
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)
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
}
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
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
null to use now.
*/
{
require_once QA_INCLUDE_DIR.'util/string.php';
require_once QA_INCLUDE_DIR.'db/post-create.php';
$tagwordids=qa_db_word_mapto_ids(array_unique(qa_tagstring_to_tags($tagstring)));
foreach ($tagwordids as $wordid)
}
/**
* 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
* to the question $questionid, and was caused by $lastuserid. Pass a unix $timestamp for the event time or leave as
* null to use now.
* @param $tagstring
* @param $questionid
* @param $updatetype
* @param $lastuserid
* @param $timestamp
*/
function qa_create_event_for_tags($tagstring, $questionid, $updatetype, $lastuserid, $timestamp = null)
{
require_once QA_INCLUDE_DIR . 'util/string.php';
require_once QA_INCLUDE_DIR . 'db/post-create.php';
$tagwordids = qa_db_word_mapto_ids(array_unique(qa_tagstring_to_tags($tagstring)));
foreach ($tagwordids as $wordid) {
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)
/*
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
$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.
*/
{
}
/**
* 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
* $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.
* @param $categoryid
* @param $questionid
* @param $updatetype
* @param $lastuserid
* @param $timestamp
*/
function qa_create_event_for_category($categoryid, $questionid, $updatetype, $lastuserid, $timestamp = null)
{
if (isset($categoryid)) {
require_once QA_INCLUDE_DIR.'db/selects.php';
require_once QA_INCLUDE_DIR.'app/format.php';
require_once QA_INCLUDE_DIR . 'db/selects.php';
require_once QA_INCLUDE_DIR . 'app/format.php';
$categories=qa_category_path(qa_db_single_select(qa_db_category_nav_selectspec($categoryid, true)), $categoryid);
foreach ($categories as $category)
$categories = qa_category_path(qa_db_single_select(qa_db_category_nav_selectspec($categoryid, true)), $categoryid);
foreach ($categories as $category) {
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
*/
\ No newline at end of file
}
......@@ -20,13 +20,13 @@
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: ../');
exit;
}
}
/**
/**
* Set an entity to be favorited or removed from favorites. Handles event reporting.
*
* @param int $userid ID of user assigned to the favorite
......@@ -36,11 +36,11 @@
* @param string $entityid ID of the entity being favorited (e.g. postid for questions)
* @param bool $favorite Whether to add favorite (true) or remove favorite (false)
*/
function qa_user_favorite_set($userid, $handle, $cookieid, $entitytype, $entityid, $favorite)
{
require_once QA_INCLUDE_DIR.'db/favorites.php';
require_once QA_INCLUDE_DIR.'app/limits.php';
require_once QA_INCLUDE_DIR.'app/updates.php';
function qa_user_favorite_set($userid, $handle, $cookieid, $entitytype, $entityid, $favorite)
{
require_once QA_INCLUDE_DIR . 'db/favorites.php';
require_once QA_INCLUDE_DIR . 'app/limits.php';
require_once QA_INCLUDE_DIR . 'app/updates.php';
// Make sure the user is not favoriting themselves
if ($entitytype == QA_ENTITY_USER && $userid == $entityid) {
......@@ -54,23 +54,23 @@
switch ($entitytype) {
case QA_ENTITY_QUESTION:
$action=$favorite ? 'q_favorite' : 'q_unfavorite';
$params=array('postid' => $entityid);
$action = $favorite ? 'q_favorite' : 'q_unfavorite';
$params = array('postid' => $entityid);
break;
case QA_ENTITY_USER:
$action=$favorite ? 'u_favorite' : 'u_unfavorite';
$params=array('userid' => $entityid);
$action = $favorite ? 'u_favorite' : 'u_unfavorite';
$params = array('userid' => $entityid);
break;
case QA_ENTITY_TAG:
$action=$favorite ? 'tag_favorite' : 'tag_unfavorite';
$params=array('wordid' => $entityid);
$action = $favorite ? 'tag_favorite' : 'tag_unfavorite';
$params = array('wordid' => $entityid);
break;
case QA_ENTITY_CATEGORY:
$action=$favorite ? 'cat_favorite' : 'cat_unfavorite';
$params=array('categoryid' => $entityid);
$action = $favorite ? 'cat_favorite' : 'cat_unfavorite';
$params = array('categoryid' => $entityid);
break;
default:
......@@ -79,15 +79,18 @@
}
qa_report_event($action, $userid, $handle, $cookieid, $params);
}
}
function qa_favorite_q_list_view($questions, $usershtml)
/*
Returns content to set in $qa_content['q_list'] for a user's favorite $questions. Pre-generated
user HTML in $usershtml.
*/
{
/**
* Returns content to set in $qa_content['q_list'] for a user's favorite $questions. Pre-generated
* user HTML in $usershtml.
* @param $questions
* @param $usershtml
* @return array
*/
function qa_favorite_q_list_view($questions, $usershtml)
{
$q_list = array(
'qs' => array(),
);
......@@ -96,7 +99,7 @@
return $q_list;
$q_list['form'] = array(
'tags' => 'method="post" action="'.qa_self_html().'"',
'tags' => 'method="post" action="' . qa_self_html() . '"',
'hidden' => array(
'code' => qa_get_form_security_code('vote'),
),
......@@ -110,24 +113,27 @@
}
return $q_list;
}
}
function qa_favorite_users_view($users, $usershtml)
/*
Returns content to set in $qa_content['ranking_users'] for a user's favorite $users. Pre-generated
user HTML in $usershtml.
*/
{
/**
* Returns content to set in $qa_content['ranking_users'] for a user's favorite $users. Pre-generated
* user HTML in $usershtml.
* @param $users
* @param $usershtml
* @return array|null
*/
function qa_favorite_users_view($users, $usershtml)
{
if (QA_FINAL_EXTERNAL_USERS)
return null;
require_once QA_INCLUDE_DIR.'app/users.php';
require_once QA_INCLUDE_DIR.'app/format.php';
require_once QA_INCLUDE_DIR . 'app/users.php';
require_once QA_INCLUDE_DIR . 'app/format.php';
$ranking = array(
'items' => array(),
'rows' => ceil(count($users)/qa_opt('columns_users')),
'rows' => ceil(count($users) / qa_opt('columns_users')),
'type' => 'users',
);
......@@ -144,20 +150,22 @@
}
return $ranking;
}
}
function qa_favorite_tags_view($tags)
/*
Returns content to set in $qa_content['ranking_tags'] for a user's favorite $tags.
*/
{
require_once QA_INCLUDE_DIR.'app/format.php';
/**
* Returns content to set in $qa_content['ranking_tags'] for a user's favorite $tags.
* @param $tags
* @return array
*/
function qa_favorite_tags_view($tags)
{
require_once QA_INCLUDE_DIR . 'app/format.php';
$ranking = array(
'items' => array(),
'rows' => ceil(count($tags)/qa_opt('columns_tags')),
'type' => 'tags'
'rows' => ceil(count($tags) / qa_opt('columns_tags')),
'type' => 'tags',
);
foreach ($tags as $tag) {
......@@ -168,15 +176,17 @@
}
return $ranking;
}
}
function qa_favorite_categories_view($categories)
/*
Returns content to set in $qa_content['nav_list_categories'] for a user's favorite $categories.
*/
{
require_once QA_INCLUDE_DIR.'app/format.php';
/**
* Returns content to set in $qa_content['nav_list_categories'] for a user's favorite $categories.
* @param $categories
* @return array
*/
function qa_favorite_categories_view($categories)
{
require_once QA_INCLUDE_DIR . 'app/format.php';
$nav_list_categories = array(
'nav' => array(),
......@@ -184,24 +194,19 @@
);
foreach ($categories as $category) {
$cat_url = qa_path_html( 'questions/' . implode( '/', array_reverse(explode('/', $category['backpath'])) ) );
$cat_url = qa_path_html('questions/' . implode('/', array_reverse(explode('/', $category['backpath']))));
$cat_anchor = $category['qcount'] == 1
? qa_lang_html_sub('main/1_question', '1', '1')
: qa_lang_html_sub('main/x_questions', qa_format_number($category['qcount'], 0, true));
$cat_descr = strlen($category['content']) ? qa_html(' - '.$category['content']) : '';
$cat_descr = strlen($category['content']) ? qa_html(' - ' . $category['content']) : '';
$nav_list_categories['nav'][$category['categoryid']] = array(
'label' => qa_html($category['title']),
'state' => 'open',
'favorited' => true,
'note' => ' - <a href="'.$cat_url.'">'.$cat_anchor.'</a>'.$cat_descr,
'note' => ' - <a href="' . $cat_url . '">' . $cat_anchor . '</a>' . $cat_descr,
);
}
return $nav_list_categories;
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
}
......@@ -133,8 +133,8 @@ function qa_limits_calc_remaining($action, $userlimits, $iplimits)
$period = (int)(qa_opt('db_time') / 3600);
return max(0, min(
$usermax - ((@$userlimits['period'] == $period) ? $userlimits['count'] : 0),
$ipmax - ((@$iplimits['period'] == $period) ? $iplimits['count'] : 0)
$usermax - (@$userlimits['period'] == $period ? $userlimits['count'] : 0),
$ipmax - (@$iplimits['period'] == $period ? $iplimits['count'] : 0)
));
}
......@@ -229,7 +229,7 @@ function qa_ip_between($ip, $startip, $endip)
if (count($uip) != count($ustartip) || count($uip) != count($uendip))
return false;
foreach ($uip as $i=>$byte) {
foreach ($uip as $i => $byte) {
if ($byte < $ustartip[$i] || $byte > $uendip[$i]) {
return false;
}
......
......@@ -20,105 +20,112 @@
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: ../');
exit;
}
}
function qa_mailing_start()
/*
Start a mailing to all users, unless one has already been started
*/
{
require_once QA_INCLUDE_DIR.'db/admin.php';
/**
* Start a mailing to all users, unless one has already been started
*/
function qa_mailing_start()
{
require_once QA_INCLUDE_DIR . '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_userid', '0');
qa_opt('mailing_total_users', qa_db_count_users());
qa_opt('mailing_done_users', 0);
}
}
}
function qa_mailing_stop()
/*
Stop a mailing to all users
*/
{
/**
* Stop a mailing to all users
*/
function qa_mailing_stop()
{
qa_opt('mailing_last_timestamp', '');
qa_opt('mailing_last_userid', '');
qa_opt('mailing_done_users', '');
qa_opt('mailing_total_users', '');
}
}
function qa_mailing_perform_step()
/*
Allow the mailing to proceed forwards, for the appropriate amount of time and users, based on the options
*/
{
require_once QA_INCLUDE_DIR.'db/users.php';
/**
* Allow the mailing to proceed forwards, for the appropriate amount of time and users, based on the options
*/
function qa_mailing_perform_step()
{
require_once QA_INCLUDE_DIR . 'db/users.php';
$lastuserid=qa_opt('mailing_last_userid');
$lastuserid = qa_opt('mailing_last_userid');
if (strlen($lastuserid)) {
$thistime=time();
$lasttime=qa_opt('mailing_last_timestamp');
$perminute=qa_opt('mailing_per_minute');
$thistime = time();
$lasttime = qa_opt('mailing_last_timestamp');
$perminute = qa_opt('mailing_per_minute');
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
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
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) {
qa_opt('mailing_last_timestamp', $thistime+30);
if ($count > 0) {
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)
$sentusers=0;
$users=qa_db_users_get_mailing_next($lastuserid, $count);
$sentusers = 0;
$users = qa_db_users_get_mailing_next($lastuserid, $count);
if (count($users)) {
foreach ($users as $user)
$lastuserid=max($lastuserid, $user['userid']);
foreach ($users as $user) {
$lastuserid = max($lastuserid, $user['userid']);
}
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)) {
qa_mailing_send_one($user['userid'], $user['handle'], $user['email'], $user['emailcode']);
$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
qa_mailing_stop();
}
}
}
function qa_mailing_send_one($userid, $handle, $email, $emailcode)
/*
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
*/
{
require_once QA_INCLUDE_DIR.'app/emails.php';
require_once QA_INCLUDE_DIR.'db/users.php';
}
/**
* 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
* @param $userid
* @param $handle
* @param $email
* @param $emailcode
* @return bool
*/
function qa_mailing_send_one($userid, $handle, $email, $emailcode)
{
require_once QA_INCLUDE_DIR . 'app/emails.php';
require_once QA_INCLUDE_DIR . 'db/users.php';
if (!strlen(trim($emailcode))) {
$emailcode=qa_db_user_rand_emailcode();
$emailcode = qa_db_user_rand_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(
'fromemail' => qa_opt('mailing_from_email'),
......@@ -126,29 +133,25 @@
'toemail' => $email,
'toname' => $handle,
'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,
));
}
}
function qa_mailing_progress_message()
/*
Return a message describing current progress in the mailing
*/
{
/**
* Return a message describing current progress in the mailing
*/
function qa_mailing_progress_message()
{
require_once QA_INCLUDE_DIR . 'app/format.php';
if (strlen(qa_opt('mailing_last_userid')))
if (strlen(qa_opt('mailing_last_userid'))) {
return strtr(qa_lang('admin/mailing_progress'), array(
'^1' => qa_format_number(qa_opt('mailing_done_users')),
'^2' => qa_format_number(qa_opt('mailing_total_users')),
));
else
return null;
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
return null;
}
......@@ -20,24 +20,28 @@
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: ../');
exit;
}
}
function qa_wall_error_html($fromuserid, $touserid, $touserflags)
/*
Returns an HTML string describing the reason why user $fromuserid cannot post on the wall of $touserid who has
user flags $touserflags. If there is no such reason the function returns false.
*/
{
require_once QA_INCLUDE_DIR.'app/limits.php';
/**
* Returns an HTML string describing the reason why user $fromuserid cannot post on the wall of $touserid who has
* user flags $touserflags. If there is no such reason the function returns false.
* @param $fromuserid
* @param $touserid
* @param $touserflags
* @return bool|mixed|string
*/
function qa_wall_error_html($fromuserid, $touserid, $touserflags)
{
require_once QA_INCLUDE_DIR . 'app/limits.php';
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
if (!QA_FINAL_EXTERNAL_USERS && qa_opt('allow_user_walls')) {
if ( ($touserflags & QA_USER_FLAGS_NO_WALL_POSTS) && !(isset($fromuserid) && $fromuserid == $touserid) )
if (($touserflags & QA_USER_FLAGS_NO_WALL_POSTS) && !(isset($fromuserid) && $fromuserid == $touserid))
return qa_lang_html('profile/post_wall_blocked');
else {
......@@ -66,19 +70,27 @@
}
return qa_lang_html('users/no_permission');
}
function qa_wall_add_post($userid, $handle, $cookieid, $touserid, $tohandle, $content, $format)
/*
Adds a post to the wall of user $touserid with handle $tohandle, containing $content in $format (e.g. '' for text or 'html')
The post is by user $userid with handle $handle, and $cookieid is the user's current cookie (used for reporting the event).
*/
{
}
/**
* Adds a post to the wall of user $touserid with handle $tohandle, containing $content in $format (e.g. '' for text or 'html')
* The post is by user $userid with handle $handle, and $cookieid is the user's current cookie (used for reporting the event).
* @param $userid
* @param $handle
* @param $cookieid
* @param $touserid
* @param $tohandle
* @param $content
* @param $format
* @return mixed
*/
function qa_wall_add_post($userid, $handle, $cookieid, $touserid, $tohandle, $content, $format)
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
require_once QA_INCLUDE_DIR.'app/format.php';
require_once QA_INCLUDE_DIR.'db/messages.php';
require_once QA_INCLUDE_DIR . 'app/format.php';
require_once QA_INCLUDE_DIR . 'db/messages.php';
$messageid = qa_db_message_create($userid, $touserid, $content, $format, true);
qa_db_user_recount_posts($touserid);
......@@ -93,16 +105,20 @@
));
return $messageid;
}
}
function qa_wall_delete_post($userid, $handle, $cookieid, $message)
/*
Deletes the wall post described in $message (as obtained via qa_db_recent_messages_selectspec()). The deletion was performed
by user $userid with handle $handle, and $cookieid is the user's current cookie (all used for reporting the event).
*/
{
require_once QA_INCLUDE_DIR.'db/messages.php';
/**
* Deletes the wall post described in $message (as obtained via qa_db_recent_messages_selectspec()). The deletion was performed
* by user $userid with handle $handle, and $cookieid is the user's current cookie (all used for reporting the event).
* @param $userid
* @param $handle
* @param $cookieid
* @param $message
*/
function qa_wall_delete_post($userid, $handle, $cookieid, $message)
{
require_once QA_INCLUDE_DIR . 'db/messages.php';
qa_db_message_delete($message['messageid']);
qa_db_user_recount_posts($message['touserid']);
......@@ -111,21 +127,24 @@
'messageid' => $message['messageid'],
'oldmessage' => $message,
));
}
function qa_wall_posts_add_rules($usermessages, $start)
/*
Return the list of messages in $usermessages (as obtained via qa_db_recent_messages_selectspec()) with additional
fields indicating what actions can be performed on them by the current user. The messages were retrieved beginning
at offset $start in the database. Currently only 'deleteable' is relevant.
*/
{
}
/**
* Return the list of messages in $usermessages (as obtained via qa_db_recent_messages_selectspec()) with additional
* fields indicating what actions can be performed on them by the current user. The messages were retrieved beginning
* at offset $start in the database. Currently only 'deleteable' is relevant.
* @param $usermessages
* @param $start
* @return mixed
*/
function qa_wall_posts_add_rules($usermessages, $start)
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
$userid = qa_get_logged_in_userid();
$userdeleteall = !(qa_user_permit_error('permit_hide_show') || qa_user_permit_error('permit_delete_hidden'));
// reuse "Hiding or showing any post" and "Deleting hidden posts" permissions
$userdeleteall = !(qa_user_permit_error('permit_hide_show') || qa_user_permit_error('permit_delete_hidden'));
$userrecent = $start == 0 && isset($userid); // User can delete all of the recent messages they wrote on someone's wall...
foreach ($usermessages as $key => $message) {
......@@ -139,16 +158,18 @@
}
return $usermessages;
}
}
function qa_wall_post_view($message)
/*
Returns an element to add to $qa_content['message_list']['messages'] for $message (as obtained via
qa_db_recent_messages_selectspec() and then qa_wall_posts_add_rules()).
*/
{
require_once QA_INCLUDE_DIR.'app/format.php';
/**
* Returns an element to add to $qa_content['message_list']['messages'] for $message (as obtained via
* qa_db_recent_messages_selectspec() and then qa_wall_posts_add_rules()).
* @param $message
* @return array
*/
function qa_wall_post_view($message)
{
require_once QA_INCLUDE_DIR . 'app/format.php';
$options = qa_message_html_defaults();
......@@ -160,7 +181,7 @@
'buttons' => array(
'delete' => array(
'tags' => 'name="m'.qa_html($message['messageid']).'_dodelete" onclick="return qa_wall_post_click('.qa_js($message['messageid']).', this);"',
'tags' => 'name="m' . qa_html($message['messageid']) . '_dodelete" onclick="return qa_wall_post_click(' . qa_js($message['messageid']) . ', this);"',
'label' => qa_lang_html('question/delete_button'),
'popup' => qa_lang_html('profile/delete_wall_post_popup'),
),
......@@ -169,35 +190,38 @@
}
return $htmlfields;
}
function qa_wall_view_more_link($handle, $start)
/*
Returns an element to add to $qa_content['message_list']['messages'] with a link to view all wall posts
*/
{
$url = qa_path_html( 'user/'.$handle.'/wall', array('start' => $start) );
}
/**
* Returns an element to add to $qa_content['message_list']['messages'] with a link to view all wall posts
* @param $handle
* @param $start
* @return array
*/
function qa_wall_view_more_link($handle, $start)
{
$url = qa_path_html('user/' . $handle . '/wall', array('start' => $start));
return array(
'content' => '<a href="'.$url.'">'.qa_lang_html('profile/wall_view_more').'</a>',
'content' => '<a href="' . $url . '">' . qa_lang_html('profile/wall_view_more') . '</a>',
);
}
function qa_pm_delete($userid, $handle, $cookieid, $message, $box)
/*
Hides the private message described in $message (as obtained via qa_db_messages_inbox_selectspec() or qa_db_messages_outbox_selectspec()).
If both sender and receiver have hidden the message, it gets deleted from the database.
Note: currently no event is reported here, so $handle/$cookieid are unused.
*/
{
require_once QA_INCLUDE_DIR.'db/messages.php';
}
/**
* Hides the private message described in $message (as obtained via qa_db_messages_inbox_selectspec() or qa_db_messages_outbox_selectspec()).
* If both sender and receiver have hidden the message, it gets deleted from the database.
* Note: currently no event is reported here, so $handle/$cookieid are unused.
* @param $userid
* @param $handle
* @param $cookieid
* @param $message
* @param $box
*/
function qa_pm_delete($userid, $handle, $cookieid, $message, $box)
{
require_once QA_INCLUDE_DIR . 'db/messages.php';
qa_db_message_user_hide($message['messageid'], $box);
qa_db_message_delete($message['messageid'], false);
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
}
......@@ -20,51 +20,67 @@
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: ../');
exit;
}
function qa_q_list_page_content($questions, $pagesize, $start, $count, $sometitle, $nonetitle,
}
/**
* Returns the $qa_content structure for a question list page showing $questions retrieved from the
* database. If $pagesize is not null, it sets the max number of questions to display. If $count is
* not null, pagination is determined by $start and $count. The page title is $sometitle unless
* there are no questions shown, in which case it's $nonetitle. $navcategories should contain the
* categories retrived from the database using qa_db_category_nav_selectspec(...) for $categoryid,
* which is the current category shown. If $categorypathprefix is set, category navigation will be
* shown, with per-category question counts if $categoryqcount is true. The nav links will have the
* prefix $categorypathprefix and possible extra $categoryparams. If $feedpathprefix is set, the
* page has an RSS feed whose URL uses that prefix. If there are no links to other pages, $suggest
* is used to suggest what the user should do. The $pagelinkparams are passed through to
* qa_html_page_links(...) which creates links for page 2, 3, etc..
* @param $questions
* @param $pagesize
* @param $start
* @param $count
* @param $sometitle
* @param $nonetitle
* @param $navcategories
* @param $categoryid
* @param $categoryqcount
* @param $categorypathprefix
* @param $feedpathprefix
* @param $suggest
* @param $pagelinkparams
* @param $categoryparams
* @param $dummy
* @return array
*/
function qa_q_list_page_content($questions, $pagesize, $start, $count, $sometitle, $nonetitle,
$navcategories, $categoryid, $categoryqcount, $categorypathprefix, $feedpathprefix, $suggest,
$pagelinkparams=null, $categoryparams=null, $dummy=null)
/*
Returns the $qa_content structure for a question list page showing $questions retrieved from the
database. If $pagesize is not null, it sets the max number of questions to display. If $count is
not null, pagination is determined by $start and $count. The page title is $sometitle unless
there are no questions shown, in which case it's $nonetitle. $navcategories should contain the
categories retrived from the database using qa_db_category_nav_selectspec(...) for $categoryid,
which is the current category shown. If $categorypathprefix is set, category navigation will be
shown, with per-category question counts if $categoryqcount is true. The nav links will have the
prefix $categorypathprefix and possible extra $categoryparams. If $feedpathprefix is set, the
page has an RSS feed whose URL uses that prefix. If there are no links to other pages, $suggest
is used to suggest what the user should do. The $pagelinkparams are passed through to
qa_html_page_links(...) which creates links for page 2, 3, etc..
*/
{
$pagelinkparams = null, $categoryparams = null, $dummy = null)
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
require_once QA_INCLUDE_DIR.'app/format.php';
require_once QA_INCLUDE_DIR.'app/updates.php';
require_once QA_INCLUDE_DIR . 'app/format.php';
require_once QA_INCLUDE_DIR . 'app/updates.php';
$userid=qa_get_logged_in_userid();
$userid = qa_get_logged_in_userid();
// Chop down to size, get user information for display
if (isset($pagesize))
$questions=array_slice($questions, 0, $pagesize);
$questions = array_slice($questions, 0, $pagesize);
$usershtml=qa_userids_handles_html(qa_any_get_userids_handles($questions));
$usershtml = qa_userids_handles_html(qa_any_get_userids_handles($questions));
// Prepare content for theme
$qa_content=qa_content_prepare(true, array_keys(qa_category_path($navcategories, $categoryid)));
$qa_content = qa_content_prepare(true, array_keys(qa_category_path($navcategories, $categoryid)));
$qa_content['q_list']['form']=array(
'tags' => 'method="post" action="'.qa_self_html().'"',
$qa_content['q_list']['form'] = array(
'tags' => 'method="post" action="' . qa_self_html() . '"',
'hidden' => array(
'code' => qa_get_form_security_code('vote'),
......@@ -92,49 +108,53 @@
$qa_content['q_list']['qs'][] = $fields;
}
}
else
} else
$qa_content['title'] = $nonetitle;
if (isset($userid) && isset($categoryid)) {
$favoritemap=qa_get_favorite_non_qs_map();
$favoritemap = qa_get_favorite_non_qs_map();
$categoryisfavorite = @$favoritemap['category'][$navcategories[$categoryid]['backpath']];
$qa_content['favorite']=qa_favorite_form(QA_ENTITY_CATEGORY, $categoryid, $categoryisfavorite,
$qa_content['favorite'] = qa_favorite_form(QA_ENTITY_CATEGORY, $categoryid, $categoryisfavorite,
qa_lang_sub($categoryisfavorite ? 'main/remove_x_favorites' : 'main/add_category_x_favorites', $navcategories[$categoryid]['title']));
}
if (isset($count) && isset($pagesize))
$qa_content['page_links']=qa_html_page_links(qa_request(), $start, $pagesize, $count, qa_opt('pages_prev_next'), $pagelinkparams);
$qa_content['page_links'] = qa_html_page_links(qa_request(), $start, $pagesize, $count, qa_opt('pages_prev_next'), $pagelinkparams);
if (empty($qa_content['page_links']))
$qa_content['suggest_next']=$suggest;
$qa_content['suggest_next'] = $suggest;
if (qa_using_categories() && count($navcategories) && isset($categorypathprefix))
$qa_content['navigation']['cat']=qa_category_navigation($navcategories, $categoryid, $categorypathprefix, $categoryqcount, $categoryparams);
$qa_content['navigation']['cat'] = qa_category_navigation($navcategories, $categoryid, $categorypathprefix, $categoryqcount, $categoryparams);
if (isset($feedpathprefix) && (qa_opt('feed_per_category') || !isset($categoryid)) )
$qa_content['feed']=array(
'url' => qa_path_html(qa_feed_request($feedpathprefix.(isset($categoryid) ? ('/'.qa_category_path_request($navcategories, $categoryid)) : ''))),
if (isset($feedpathprefix) && (qa_opt('feed_per_category') || !isset($categoryid)))
$qa_content['feed'] = array(
'url' => qa_path_html(qa_feed_request($feedpathprefix . (isset($categoryid) ? ('/' . qa_category_path_request($navcategories, $categoryid)) : ''))),
'label' => strip_tags($sometitle),
);
return $qa_content;
}
/**
* Return the sub navigation structure common to question listing pages
* @param $sort
* @param $categoryslugs
* @return array
*/
function qa_qs_sub_navigation($sort, $categoryslugs)
{
$request = 'questions';
if (isset($categoryslugs)) {
foreach ($categoryslugs as $slug) {
$request .= '/' . $slug;
}
}
function qa_qs_sub_navigation($sort, $categoryslugs)
/*
Return the sub navigation structure common to question listing pages
*/
{
$request='questions';
if (isset($categoryslugs))
foreach ($categoryslugs as $slug)
$request.='/'.$slug;
$navigation=array(
$navigation = array(
'recent' => array(
'label' => qa_lang('main/nav_most_recent'),
'url' => qa_path_html($request),
......@@ -162,29 +182,34 @@
);
if (isset($navigation[$sort]))
$navigation[$sort]['selected']=true;
$navigation[$sort]['selected'] = true;
else
$navigation['recent']['selected']=true;
$navigation['recent']['selected'] = true;
if (!qa_opt('do_count_q_views'))
unset($navigation['views']);
return $navigation;
}
/**
* Return the sub navigation structure common to unanswered pages
* @param $by
* @param $categoryslugs
* @return array
*/
function qa_unanswered_sub_navigation($by, $categoryslugs)
{
$request = 'unanswered';
if (isset($categoryslugs)) {
foreach ($categoryslugs as $slug) {
$request .= '/' . $slug;
}
}
function qa_unanswered_sub_navigation($by, $categoryslugs)
/*
Return the sub navigation structure common to unanswered pages
*/
{
$request='unanswered';
if (isset($categoryslugs))
foreach ($categoryslugs as $slug)
$request.='/'.$slug;
$navigation=array(
$navigation = array(
'by-answers' => array(
'label' => qa_lang('main/nav_no_answer'),
'url' => qa_path_html($request),
......@@ -201,18 +226,13 @@
),
);
if (isset($navigation['by-'.$by]))
$navigation['by-'.$by]['selected']=true;
if (isset($navigation['by-' . $by]))
$navigation['by-' . $by]['selected'] = true;
else
$navigation['by-answers']['selected']=true;
$navigation['by-answers']['selected'] = true;
if (!qa_opt('voting_on_as'))
unset($navigation['by-upvotes']);
return $navigation;
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
}
......@@ -20,67 +20,73 @@
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: ../');
exit;
}
function qa_get_search_results($query, $start, $count, $userid, $absoluteurls, $fullcontent)
/*
Returns $count search results for $query performed by $userid, starting at offset $start. Set $absoluteurls to true
to get absolute URLs for the results and $fullcontent if the results should include full post content. This calls
through to the chosen search module, and performs all the necessary post-processing to supplement the results for
display online or in an RSS feed.
*/
{
}
/**
* Returns $count search results for $query performed by $userid, starting at offset $start. Set $absoluteurls to true
* to get absolute URLs for the results and $fullcontent if the results should include full post content. This calls
* through to the chosen search module, and performs all the necessary post-processing to supplement the results for
* display online or in an RSS feed.
* @param $query
* @param $start
* @param $count
* @param $userid
* @param $absoluteurls
* @param $fullcontent
* @return
*/
function qa_get_search_results($query, $start, $count, $userid, $absoluteurls, $fullcontent)
{
// Identify which search module should be used
$searchmodules=qa_load_modules_with('search', 'process_search');
$searchmodules = qa_load_modules_with('search', 'process_search');
if (!count($searchmodules))
qa_fatal_error('No search engine is available');
$module=reset($searchmodules); // use first one by default
$module = reset($searchmodules); // use first one by default
if (count($searchmodules)>1) {
$tryname=qa_opt('search_module'); // use chosen one if it's available
if (count($searchmodules) > 1) {
$tryname = qa_opt('search_module'); // use chosen one if it's available
if (isset($searchmodules[$tryname]))
$module=$searchmodules[$tryname];
$module = $searchmodules[$tryname];
}
// Get the results
$results=$module->process_search($query, $start, $count, $userid, $absoluteurls, $fullcontent);
$results = $module->process_search($query, $start, $count, $userid, $absoluteurls, $fullcontent);
// Work out what additional information (if any) we need to retrieve for the results
$keypostidgetfull=array();
$keypostidgettype=array();
$keypostidgetquestion=array();
$keypageidgetpage=array();
$keypostidgetfull = array();
$keypostidgettype = array();
$keypostidgetquestion = array();
$keypageidgetpage = array();
foreach ($results as $result) {
if (isset($result['question_postid']) && !isset($result['question']))
$keypostidgetfull[$result['question_postid']]=true;
$keypostidgetfull[$result['question_postid']] = true;
if (isset($result['match_postid'])) {
if (!( (isset($result['question_postid'])) || (isset($result['question'])) ))
$keypostidgetquestion[$result['match_postid']]=true; // we can also get $result['match_type'] from this
if (!((isset($result['question_postid'])) || (isset($result['question']))))
$keypostidgetquestion[$result['match_postid']] = true; // we can also get $result['match_type'] from this
elseif (!isset($result['match_type']))
$keypostidgettype[$result['match_postid']]=true;
$keypostidgettype[$result['match_postid']] = true;
}
if (isset($result['page_pageid']) && !isset($result['page']))
$keypageidgetpage[$result['page_pageid']]=true;
$keypageidgetpage[$result['page_pageid']] = true;
}
// Perform the appropriate database queries
list($postidfull, $postidtype, $postidquestion, $pageidpage)=qa_db_select_with_pending(
list($postidfull, $postidtype, $postidquestion, $pageidpage) = qa_db_select_with_pending(
count($keypostidgetfull) ? qa_db_posts_selectspec($userid, array_keys($keypostidgetfull), $fullcontent) : null,
count($keypostidgettype) ? qa_db_posts_basetype_selectspec(array_keys($keypostidgettype)) : null,
count($keypostidgetquestion) ? qa_db_posts_to_qs_selectspec($userid, array_keys($keypostidgetquestion), $fullcontent) : null,
......@@ -91,50 +97,45 @@
foreach ($results as $key => $result) {
if (isset($result['question_postid']) && !isset($result['question']))
if (@$postidfull[$result['question_postid']]['basetype']=='Q')
$result['question']=@$postidfull[$result['question_postid']];
if (@$postidfull[$result['question_postid']]['basetype'] == 'Q')
$result['question'] = @$postidfull[$result['question_postid']];
if (isset($result['match_postid'])) {
if (!( (isset($result['question_postid'])) || (isset($result['question'])) )) {
$result['question']=@$postidquestion[$result['match_postid']];
if (!(isset($result['question_postid']) || isset($result['question']))) {
$result['question'] = @$postidquestion[$result['match_postid']];
if (!isset($result['match_type']))
$result['match_type']=@$result['question']['obasetype'];
$result['match_type'] = @$result['question']['obasetype'];
} elseif (!isset($result['match_type']))
$result['match_type']=@$postidtype[$result['match_postid']];
$result['match_type'] = @$postidtype[$result['match_postid']];
}
if (isset($result['question']) && !isset($result['question_postid']))
$result['question_postid']=$result['question']['postid'];
$result['question_postid'] = $result['question']['postid'];
if (isset($result['page_pageid']) && !isset($result['page']))
$result['page']=@$pageidpage[$result['page_pageid']];
$result['page'] = @$pageidpage[$result['page_pageid']];
if (!isset($result['title'])) {
if (isset($result['question']))
$result['title']=$result['question']['title'];
$result['title'] = $result['question']['title'];
elseif (isset($result['page']))
$result['title']=$result['page']['heading'];
$result['title'] = $result['page']['heading'];
}
if (!isset($result['url'])) {
if (isset($result['question']))
$result['url']=qa_q_path($result['question']['postid'], $result['question']['title'],
$result['url'] = qa_q_path($result['question']['postid'], $result['question']['title'],
$absoluteurls, @$result['match_type'], @$result['match_postid']);
elseif (isset($result['page']))
$result['url']=qa_path($result['page']['tags'], null, qa_opt('site_url'));
$result['url'] = qa_path($result['page']['tags'], null, qa_opt('site_url'));
}
$results[$key]=$result;
$results[$key] = $result;
}
// Return the results
return $results;
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
}
......@@ -20,39 +20,35 @@
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: ../');
exit;
}
}
// Character codes for the different types of entity that can be followed (entitytype columns)
define('QA_ENTITY_QUESTION', 'Q');
define('QA_ENTITY_USER', 'U');
define('QA_ENTITY_TAG', 'T');
define('QA_ENTITY_CATEGORY', 'C');
define('QA_ENTITY_NONE', '-');
define('QA_ENTITY_QUESTION', 'Q');
define('QA_ENTITY_USER', 'U');
define('QA_ENTITY_TAG', 'T');
define('QA_ENTITY_CATEGORY', 'C');
define('QA_ENTITY_NONE', '-');
// Character codes for the different types of updates on a post (updatetype columns)
define('QA_UPDATE_CATEGORY', 'A'); // questions only, category changed
define('QA_UPDATE_CLOSED', 'C'); // questions only, closed or reopened
define('QA_UPDATE_CONTENT', 'E'); // title or content edited
define('QA_UPDATE_PARENT', 'M'); // e.g. comment moved when converting its parent answer to a comment
define('QA_UPDATE_SELECTED', 'S'); // answers only, removed if unselected
define('QA_UPDATE_TAGS', 'T'); // questions only
define('QA_UPDATE_TYPE', 'Y'); // e.g. answer to comment
define('QA_UPDATE_VISIBLE', 'H'); // hidden or reshown
define('QA_UPDATE_CATEGORY', 'A'); // questions only, category changed
define('QA_UPDATE_CLOSED', 'C'); // questions only, closed or reopened
define('QA_UPDATE_CONTENT', 'E'); // title or content edited
define('QA_UPDATE_PARENT', 'M'); // e.g. comment moved when converting its parent answer to a comment
define('QA_UPDATE_SELECTED', 'S'); // answers only, removed if unselected
define('QA_UPDATE_TAGS', 'T'); // questions only
define('QA_UPDATE_TYPE', 'Y'); // e.g. answer to comment
define('QA_UPDATE_VISIBLE', 'H'); // hidden or reshown
// Character codes for types of update that only appear in the streams tables, not on the posts themselves
define('QA_UPDATE_FOLLOWS', 'F'); // if a new question was asked related to one of its answers, or for a comment that follows another
define('QA_UPDATE_C_FOR_Q', 'U'); // if comment created was on a question of the user whose stream this appears in
define('QA_UPDATE_C_FOR_A', 'N'); // if comment created was on an answer of the user whose stream this appears in
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
define('QA_UPDATE_FOLLOWS', 'F'); // if a new question was asked related to one of its answers, or for a comment that follows another
define('QA_UPDATE_C_FOR_Q', 'U'); // if comment created was on a question of the user whose stream this appears in
define('QA_UPDATE_C_FOR_A', 'N'); // if comment created was on an answer of the user whose stream this appears in
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