Commit f5aaabc6 by Scott

Coding style (db functions)

parent b8eaff85
...@@ -20,91 +20,103 @@ ...@@ -20,91 +20,103 @@
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_db_blob_create($content, $format, $sourcefilename=null, $userid=null, $cookieid=null, $ip=null) /**
/* * Create a new blob in the database with $content and $format, other fields as provided
Create a new blob in the database with $content and $format, other fields as provided * @param $content
*/ * @param $format
{ * @param $sourcefilename
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); } * @param $userid
* @param $cookieid
for ($attempt=0; $attempt<10; $attempt++) { * @param $ip
$blobid=qa_db_random_bigint(); * @return mixed|null|string
*/
if (qa_db_blob_exists($blobid)) function qa_db_blob_create($content, $format, $sourcefilename = null, $userid = null, $cookieid = null, $ip = null)
continue; {
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
qa_db_query_sub(
'INSERT INTO ^blobs (blobid, format, content, filename, userid, cookieid, createip, created) VALUES (#, $, $, $, $, #, $, NOW())', for ($attempt = 0; $attempt < 10; $attempt++) {
$blobid, $format, $content, $sourcefilename, $userid, $cookieid, @inet_pton($ip) $blobid = qa_db_random_bigint();
);
if (qa_db_blob_exists($blobid))
return $blobid; continue;
}
return null;
}
function qa_db_blob_read($blobid)
/*
Get the information about blob $blobid from the database
*/
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
return qa_db_read_one_assoc(qa_db_query_sub(
'SELECT content, format, filename FROM ^blobs WHERE blobid=#',
$blobid
), true);
}
function qa_db_blob_set_content($blobid, $content)
/*
Change the content of blob $blobid in the database to $content (can also be null)
*/
{
qa_db_query_sub(
'UPDATE ^blobs SET content=$ WHERE blobid=#',
$content, $blobid
);
}
function qa_db_blob_delete($blobid)
/*
Delete blob $blobid in the database
*/
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
qa_db_query_sub( qa_db_query_sub(
'DELETE FROM ^blobs WHERE blobid=#', 'INSERT INTO ^blobs (blobid, format, content, filename, userid, cookieid, createip, created) VALUES (#, $, $, $, $, #, $, NOW())',
$blobid $blobid, $format, $content, $sourcefilename, $userid, $cookieid, @inet_pton($ip)
); );
}
function qa_db_blob_exists($blobid) return $blobid;
/*
Check if blob $blobid exists in the database
*/
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
return qa_db_read_one_value(qa_db_query_sub(
'SELECT COUNT(*) FROM ^blobs WHERE blobid=#',
$blobid
)) > 0;
} }
return null;
/* }
Omit PHP closing tag to help avoid accidental output
*/
/**
* Get the information about blob $blobid from the database
* @param $blobid
* @return array|mixed|null
*/
function qa_db_blob_read($blobid)
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
return qa_db_read_one_assoc(qa_db_query_sub(
'SELECT content, format, filename FROM ^blobs WHERE blobid=#',
$blobid
), true);
}
/**
* Change the content of blob $blobid in the database to $content (can also be null)
* @param $blobid
* @param $content
*/
function qa_db_blob_set_content($blobid, $content)
{
qa_db_query_sub(
'UPDATE ^blobs SET content=$ WHERE blobid=#',
$content, $blobid
);
}
/**
* Delete blob $blobid in the database
* @param $blobid
* @return mixed
*/
function qa_db_blob_delete($blobid)
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
qa_db_query_sub(
'DELETE FROM ^blobs WHERE blobid=#',
$blobid
);
}
/**
* Check if blob $blobid exists in the database
* @param $blobid
* @return bool|mixed
*/
function qa_db_blob_exists($blobid)
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
$blob = qa_db_read_one_value(qa_db_query_sub(
'SELECT COUNT(*) FROM ^blobs WHERE blobid=#',
$blobid
));
return $blob > 0;
}
...@@ -20,56 +20,58 @@ ...@@ -20,56 +20,58 @@
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.'db/maxima.php'; require_once QA_INCLUDE_DIR . 'db/maxima.php';
function qa_db_cache_set($type, $cacheid, $content) /**
/* * Create (or replace) the item ($type, $cacheid) in the database cache table with $content
Create (or replace) the item ($type, $cacheid) in the database cache table with $content * @param $type
*/ * @param $cacheid
{ * @param $content
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); } * @return mixed
*/
function qa_db_cache_set($type, $cacheid, $content)
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
qa_db_query_sub(
'DELETE FROM ^cache WHERE lastread<NOW()-INTERVAL # SECOND',
QA_DB_MAX_CACHE_AGE
);
qa_db_query_sub(
'INSERT INTO ^cache (type, cacheid, content, created, lastread) VALUES ($, #, $, NOW(), NOW()) ' .
'ON DUPLICATE KEY UPDATE content = VALUES(content), created = VALUES(created), lastread = VALUES(lastread)',
$type, $cacheid, $content
);
}
/**
* Retrieve the item ($type, $cacheid) from the database cache table
* @param $type
* @param $cacheid
* @return mixed|null
*/
function qa_db_cache_get($type, $cacheid)
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
$content = qa_db_read_one_value(qa_db_query_sub(
'SELECT content FROM ^cache WHERE type=$ AND cacheid=#',
$type, $cacheid
), true);
if (isset($content))
qa_db_query_sub( qa_db_query_sub(
'DELETE FROM ^cache WHERE lastread<NOW()-INTERVAL # SECOND', 'UPDATE ^cache SET lastread=NOW() WHERE type=$ AND cacheid=#',
QA_DB_MAX_CACHE_AGE
);
qa_db_query_sub(
'INSERT INTO ^cache (type, cacheid, content, created, lastread) VALUES ($, #, $, NOW(), NOW()) ' .
'ON DUPLICATE KEY UPDATE content = VALUES(content), created = VALUES(created), lastread = VALUES(lastread)',
$type, $cacheid, $content
);
}
function qa_db_cache_get($type, $cacheid)
/*
Retrieve the item ($type, $cacheid) from the database cache table
*/
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
$content=qa_db_read_one_value(qa_db_query_sub(
'SELECT content FROM ^cache WHERE type=$ AND cacheid=#',
$type, $cacheid $type, $cacheid
), true); );
if (isset($content))
qa_db_query_sub(
'UPDATE ^cache SET lastread=NOW() WHERE type=$ AND cacheid=#',
$type, $cacheid
);
return $content;
}
/* return $content;
Omit PHP closing tag to help avoid accidental output }
*/
\ No newline at end of file
...@@ -20,60 +20,63 @@ ...@@ -20,60 +20,63 @@
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_db_cookie_create($ipaddress)
/*
Create a new random cookie for $ipaddress and insert into database, returning it
*/
{
for ($attempt=0; $attempt<10; $attempt++) {
$cookieid=qa_db_random_bigint();
if (qa_db_cookie_exists($cookieid))
continue;
qa_db_query_sub( /**
'INSERT INTO ^cookies (cookieid, created, createip) '. * Create a new random cookie for $ipaddress and insert into database, returning it
'VALUES (#, NOW(), $)', * @param $ipaddress
$cookieid, @inet_pton($ipaddress) * @return null|string
); */
function qa_db_cookie_create($ipaddress)
{
for ($attempt = 0; $attempt < 10; $attempt++) {
$cookieid = qa_db_random_bigint();
return $cookieid; if (qa_db_cookie_exists($cookieid))
} continue;
return null;
}
function qa_db_cookie_written($cookieid, $ipaddress)
/*
Note in database that a write operation has been done by user identified by $cookieid and from $ipaddress
*/
{
qa_db_query_sub( qa_db_query_sub(
'UPDATE ^cookies SET written=NOW(), writeip=$ WHERE cookieid=#', 'INSERT INTO ^cookies (cookieid, created, createip) ' .
@inet_pton($ipaddress), $cookieid 'VALUES (#, NOW(), $)',
$cookieid, @inet_pton($ipaddress)
); );
}
return $cookieid;
function qa_db_cookie_exists($cookieid)
/*
Return whether $cookieid exists in database
*/
{
return qa_db_read_one_value(qa_db_query_sub(
'SELECT COUNT(*) FROM ^cookies WHERE cookieid=#',
$cookieid
)) > 0;
} }
return null;
/* }
Omit PHP closing tag to help avoid accidental output
*/
/**
* Note in database that a write operation has been done by user identified by $cookieid and from $ipaddress
* @param $cookieid
* @param $ipaddress
*/
function qa_db_cookie_written($cookieid, $ipaddress)
{
qa_db_query_sub(
'UPDATE ^cookies SET written=NOW(), writeip=$ WHERE cookieid=#',
@inet_pton($ipaddress), $cookieid
);
}
/**
* Return whether $cookieid exists in database
* @param $cookieid
* @return bool
*/
function qa_db_cookie_exists($cookieid)
{
$cookie = qa_db_read_one_value(qa_db_query_sub(
'SELECT COUNT(*) FROM ^cookies WHERE cookieid=#',
$cookieid
));
return $cookie > 0;
}
...@@ -20,10 +20,10 @@ ...@@ -20,10 +20,10 @@
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;
} }
/* /*
...@@ -103,103 +103,104 @@ ...@@ -103,103 +103,104 @@
*/ */
function qa_db_favorite_create($userid, $entitytype, $entityid) /**
/* * Add the entity $entitytype with $entityid to the favorites list of $userid. Handles switching streams across from
Add the entity $entitytype with $entityid to the favorites list of $userid. Handles switching streams across from * per-user to per-entity based on how many other users have favorited the entity (see long explanation above). If
per-user to per-entity based on how many other users have favorited the entity (see long explanation above). If * appropriate, it also adds recent events from that entity to the user's event stream.
appropriate, it also adds recent events from that entity to the user's event stream. * @param $userid
*/ * @param $entitytype
{ * @param $entityid
$threshold=qa_opt('max_copy_user_updates'); // if this many users subscribe to it, create a shared stream */
function qa_db_favorite_create($userid, $entitytype, $entityid)
{
$threshold = qa_opt('max_copy_user_updates'); // if this many users subscribe to it, create a shared stream
// Add in the favorite for this user, unshared events at first (will be switched later if appropriate) // Add in the favorite for this user, unshared events at first (will be switched later if appropriate)
qa_db_query_sub( qa_db_query_sub(
'INSERT IGNORE INTO ^userfavorites (userid, entitytype, entityid, nouserevents) VALUES ($, $, #, 0)', 'INSERT IGNORE INTO ^userfavorites (userid, entitytype, entityid, nouserevents) VALUES ($, $, #, 0)',
$userid, $entitytype, $entityid $userid, $entitytype, $entityid
); );
// See whether this entity already has another favoriter who uses its shared event stream // See whether this entity already has another favoriter who uses its shared event stream
$useshared=qa_db_read_one_value(qa_db_query_sub( $useshared = qa_db_read_one_value(qa_db_query_sub(
'SELECT COUNT(*) FROM ^userfavorites WHERE entitytype=$ AND entityid=# AND nouserevents>0 LIMIT 1', 'SELECT COUNT(*) FROM ^userfavorites WHERE entitytype=$ AND entityid=# AND nouserevents>0 LIMIT 1',
$entitytype, $entityid $entitytype, $entityid
)); ));
// If not, check whether it's time to switch it over to a shared stream // If not, check whether it's time to switch it over to a shared stream
if (!$useshared) { if (!$useshared) {
$favoriters=qa_db_read_one_value(qa_db_query_sub( $favoriters = qa_db_read_one_value(qa_db_query_sub(
'SELECT COUNT(*) FROM ^userfavorites WHERE entitytype=$ AND entityid=# LIMIT #', 'SELECT COUNT(*) FROM ^userfavorites WHERE entitytype=$ AND entityid=# LIMIT #',
$entitytype, $entityid, $threshold $entitytype, $entityid, $threshold
)); ));
$useshared=($favoriters >= $threshold);
}
// If we're going to use the shared stream...
if ($useshared) {
// ... for all the people for whom we're switching this to a shared stream, find the highest number of other shared streams they have
$maxshared=qa_db_read_one_value(qa_db_query_sub(
'SELECT MAX(c) FROM (SELECT COUNT(*) AS c FROM ^userfavorites AS shared JOIN ^userfavorites AS unshared '.
'WHERE shared.userid=unshared.userid AND shared.nouserevents>0 AND unshared.entitytype=$ AND unshared.entityid=# AND unshared.nouserevents=0 GROUP BY shared.userid) y',
$entitytype, $entityid
));
// ... if this number is greater than our current 'max_copy_user_updates' threshold, increase that threshold (see long comment above) $useshared = ($favoriters >= $threshold);
}
if (($maxshared+1)>$threshold) // If we're going to use the shared stream...
qa_opt('max_copy_user_updates', $maxshared+1);
// ... now switch all unshared favoriters (including this new one) over to be shared if ($useshared) {
qa_db_query_sub( // ... for all the people for whom we're switching this to a shared stream, find the highest number of other shared streams they have
'UPDATE ^userfavorites SET nouserevents=1 WHERE entitytype=$ AND entityid=# AND nouserevents=0',
$entitytype, $entityid
);
// Otherwise if we're going to record this in user-specific streams ... $maxshared = qa_db_read_one_value(qa_db_query_sub(
'SELECT MAX(c) FROM (SELECT COUNT(*) AS c FROM ^userfavorites AS shared JOIN ^userfavorites AS unshared ' .
'WHERE shared.userid=unshared.userid AND shared.nouserevents>0 AND unshared.entitytype=$ AND unshared.entityid=# AND unshared.nouserevents=0 GROUP BY shared.userid) y',
$entitytype, $entityid
));
} else { // ... if this number is greater than our current 'max_copy_user_updates' threshold, increase that threshold (see long comment above)
require_once QA_INCLUDE_DIR.'db/events.php';
// ... copy across recent events from the shared stream if (($maxshared + 1) > $threshold)
qa_opt('max_copy_user_updates', $maxshared + 1);
qa_db_query_sub( // ... now switch all unshared favoriters (including this new one) over to be shared
'INSERT INTO ^userevents (userid, entitytype, entityid, questionid, lastpostid, updatetype, lastuserid, updated) '.
'SELECT #, entitytype, entityid, questionid, lastpostid, updatetype, lastuserid, updated FROM '.
'^sharedevents WHERE entitytype=$ AND entityid=#',
$userid, $entitytype, $entityid
);
// ... and truncate the user's stream as appropriate qa_db_query_sub(
'UPDATE ^userfavorites SET nouserevents=1 WHERE entitytype=$ AND entityid=# AND nouserevents=0',
$entitytype, $entityid
);
qa_db_user_events_truncate($userid); } else {
} // Otherwise if we're going to record this in user-specific streams ...
}
require_once QA_INCLUDE_DIR . 'db/events.php';
function qa_db_favorite_delete($userid, $entitytype, $entityid) // ... copy across recent events from the shared stream
/*
Delete the entity $entitytype with $entityid from the favorites list of $userid, removing any corresponding events
from the user's stream.
*/
{
qa_db_query_sub(
'DELETE FROM ^userfavorites WHERE userid=$ AND entitytype=$ AND entityid=#',
$userid, $entitytype, $entityid
);
qa_db_query_sub( qa_db_query_sub(
'DELETE FROM ^userevents WHERE userid=$ AND entitytype=$ AND entityid=#', 'INSERT INTO ^userevents (userid, entitytype, entityid, questionid, lastpostid, updatetype, lastuserid, updated) ' .
'SELECT #, entitytype, entityid, questionid, lastpostid, updatetype, lastuserid, updated FROM ' .
'^sharedevents WHERE entitytype=$ AND entityid=#',
$userid, $entitytype, $entityid $userid, $entitytype, $entityid
); );
}
// ... and truncate the user's stream as appropriate
/* qa_db_user_events_truncate($userid);
Omit PHP closing tag to help avoid accidental output }
*/ }
\ No newline at end of file
/**
* Delete the entity $entitytype with $entityid from the favorites list of $userid, removing any corresponding events
* from the user's stream.
* @param $userid
* @param $entitytype
* @param $entityid
*/
function qa_db_favorite_delete($userid, $entitytype, $entityid)
{
qa_db_query_sub(
'DELETE FROM ^userfavorites WHERE userid=$ AND entitytype=$ AND entityid=#',
$userid, $entitytype, $entityid
);
qa_db_query_sub(
'DELETE FROM ^userevents WHERE userid=$ AND entitytype=$ AND entityid=#',
$userid, $entitytype, $entityid
);
}
...@@ -20,57 +20,56 @@ ...@@ -20,57 +20,56 @@
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_db_hotness_update($firstpostid, $lastpostid=null, $viewincrement=false) /**
/* * Recalculate the hotness in the database for posts $firstpostid to $lastpostid (if specified)
Recalculate the hotness in the database for posts $firstpostid to $lastpostid (if specified) * If $viewincrement is true, also increment the views counter for the post (if different IP from last view),
If $viewincrement is true, also increment the views counter for the post (if different IP from last view), * and include that in the hotness calculation
and include that in the hotness calculation * @param $firstpostid
*/ * @param $lastpostid
{ * @param bool $viewincrement
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); } * @return mixed
*/
if (qa_should_update_counts()) { function qa_db_hotness_update($firstpostid, $lastpostid=null, $viewincrement=false)
if (!isset($lastpostid)) {
$lastpostid=$firstpostid; if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
$query= "UPDATE ^posts AS x, (SELECT parents.postid, parents.created AS qcreated, COALESCE(MAX(children.created), parents.created) as acreated, COUNT(children.postid) AS acount, parents.netvotes, parents.views FROM ^posts AS parents LEFT JOIN ^posts AS children ON parents.postid=children.parentid AND children.type='A' WHERE parents.postid>=# AND parents.postid<=# AND LEFT(parents.type, 1)='Q' GROUP BY postid) AS a SET x.hotness=(". if (qa_should_update_counts()) {
'((TO_DAYS(a.qcreated)-734138)*86400.0+TIME_TO_SEC(a.qcreated))*# + '. // zero-point is Jan 1, 2010 if (!isset($lastpostid))
'((TO_DAYS(a.acreated)-734138)*86400.0+TIME_TO_SEC(a.acreated))*# + '. $lastpostid = $firstpostid;
'(a.acount+0.0)*# + '.
'(a.netvotes+0.0)*# + '. $query = "UPDATE ^posts AS x, (SELECT parents.postid, parents.created AS qcreated, COALESCE(MAX(children.created), parents.created) as acreated, COUNT(children.postid) AS acount, parents.netvotes, parents.views FROM ^posts AS parents LEFT JOIN ^posts AS children ON parents.postid=children.parentid AND children.type='A' WHERE parents.postid>=# AND parents.postid<=# AND LEFT(parents.type, 1)='Q' GROUP BY postid) AS a SET x.hotness=(" .
'(a.views+0.0+#)*#'. '((TO_DAYS(a.qcreated)-734138)*86400.0+TIME_TO_SEC(a.qcreated))*# + ' . // zero-point is Jan 1, 2010
')'.($viewincrement ? ', x.views=x.views+1, x.lastviewip=$' : ''). '((TO_DAYS(a.acreated)-734138)*86400.0+TIME_TO_SEC(a.acreated))*# + ' .
' WHERE x.postid=a.postid'.($viewincrement ? ' AND (x.lastviewip IS NULL OR x.lastviewip!=$)' : ''); '(a.acount+0.0)*# + ' .
'(a.netvotes+0.0)*# + ' .
// Additional multiples based on empirical analysis of activity on Q2A meta site to give approx equal influence for all factors '(a.views+0.0+#)*#' .
')' . ($viewincrement ? ', x.views=x.views+1, x.lastviewip=$' : '') .
$arguments=array( ' WHERE x.postid=a.postid' . ($viewincrement ? ' AND (x.lastviewip IS NULL OR x.lastviewip!=$)' : '');
$firstpostid,
$lastpostid, // Additional multiples based on empirical analysis of activity on Q2A meta site to give approx equal influence for all factors
qa_opt('hot_weight_q_age'),
qa_opt('hot_weight_a_age'), $arguments = array(
qa_opt('hot_weight_answers')*160000, $firstpostid,
qa_opt('hot_weight_votes')*160000, $lastpostid,
$viewincrement ? 1 : 0, qa_opt('hot_weight_q_age'),
qa_opt('hot_weight_views')*4000, qa_opt('hot_weight_a_age'),
); qa_opt('hot_weight_answers') * 160000,
qa_opt('hot_weight_votes') * 160000,
if ($viewincrement) { $viewincrement ? 1 : 0,
$ipbin = @inet_pton(qa_remote_ip_address()); qa_opt('hot_weight_views') * 4000,
array_push($arguments, $ipbin, $ipbin); );
}
if ($viewincrement) {
qa_db_query_raw(qa_db_apply_sub($query, $arguments)); $ipbin = @inet_pton(qa_remote_ip_address());
array_push($arguments, $ipbin, $ipbin);
} }
}
qa_db_query_raw(qa_db_apply_sub($query, $arguments));
/* }
Omit PHP closing tag to help avoid accidental output }
*/
...@@ -20,68 +20,75 @@ ...@@ -20,68 +20,75 @@
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;
}
/**
* Get rate limit information for $action from the database for user $userid and/or IP address $ip, if they're set.
* Return as an array with the limit type in the key, and a labelled array of the period and count.
* @param $userid
* @param $ip
* @param $action
* @return array
*/
function qa_db_limits_get($userid, $ip, $action)
{
$selects = array();
$arguments = array();
if (isset($userid)) {
$selects[] = "(SELECT 'user' AS limitkey, period, count FROM ^userlimits WHERE userid=$ AND action=$)";
$arguments[] = $userid;
$arguments[] = $action;
} }
if (isset($ip)) {
function qa_db_limits_get($userid, $ip, $action) $selects[] = "(SELECT 'ip' AS limitkey, period, count FROM ^iplimits WHERE ip=$ AND action=$)";
/* $arguments[] = @inet_pton($ip);
Get rate limit information for $action from the database for user $userid and/or IP address $ip, if they're set. $arguments[] = $action;
Return as an array with the limit type in the key, and a labelled array of the period and count.
*/
{
$selects=array();
$arguments=array();
if (isset($userid)) {
$selects[]="(SELECT 'user' AS limitkey, period, count FROM ^userlimits WHERE userid=$ AND action=$)";
$arguments[]=$userid;
$arguments[]=$action;
}
if (isset($ip)) {
$selects[]="(SELECT 'ip' AS limitkey, period, count FROM ^iplimits WHERE ip=$ AND action=$)";
$arguments[]=@inet_pton($ip);
$arguments[]=$action;
}
if (count($selects)) {
$query=qa_db_apply_sub(implode(' UNION ALL ', $selects), $arguments);
return qa_db_read_all_assoc(qa_db_query_raw($query), 'limitkey');
} else
return array();
}
function qa_db_limits_user_add($userid, $action, $period, $count)
/*
Increment the database rate limit count for user $userid and $action by $count within $period
*/
{
qa_db_query_sub(
'INSERT INTO ^userlimits (userid, action, period, count) VALUES ($, $, #, #) '.
'ON DUPLICATE KEY UPDATE count=IF(period=#, count+#, #), period=#',
$userid, $action, $period, $count, $period, $count, $count, $period
);
} }
if (count($selects)) {
function qa_db_limits_ip_add($ip, $action, $period, $count) $query = qa_db_apply_sub(implode(' UNION ALL ', $selects), $arguments);
/* return qa_db_read_all_assoc(qa_db_query_raw($query), 'limitkey');
Increment the database rate limit count for IP address $ip and $action by $count within $period
*/ } else
{ return array();
qa_db_query_sub( }
'INSERT INTO ^iplimits (ip, action, period, count) VALUES ($, $, #, #) '.
'ON DUPLICATE KEY UPDATE count=IF(period=#, count+#, #), period=#',
@inet_pton($ip), $action, $period, $count, $period, $count, $count, $period /**
); * Increment the database rate limit count for user $userid and $action by $count within $period
} * @param $userid
* @param $action
* @param $period
/* * @param $count
Omit PHP closing tag to help avoid accidental output */
*/ function qa_db_limits_user_add($userid, $action, $period, $count)
{
qa_db_query_sub(
'INSERT INTO ^userlimits (userid, action, period, count) VALUES ($, $, #, #) ' .
'ON DUPLICATE KEY UPDATE count=IF(period=#, count+#, #), period=#',
$userid, $action, $period, $count, $period, $count, $count, $period
);
}
/**
* Increment the database rate limit count for IP address $ip and $action by $count within $period
* @param $ip
* @param $action
* @param $period
* @param $count
*/
function qa_db_limits_ip_add($ip, $action, $period, $count)
{
qa_db_query_sub(
'INSERT INTO ^iplimits (ip, action, period, count) VALUES ($, $, #, #) ' .
'ON DUPLICATE KEY UPDATE count=IF(period=#, count+#, #), period=#',
@inet_pton($ip), $action, $period, $count, $period, $count, $count, $period
);
}
...@@ -20,54 +20,49 @@ ...@@ -20,54 +20,49 @@
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;
} }
// Maximum column sizes - any of these can be defined in qa-config.php to override the defaults below, // Maximum column sizes - any of these can be defined in qa-config.php to override the defaults below,
// but you need to do so before creating the database, otherwise it's too late. // but you need to do so before creating the database, otherwise it's too late.
@define('QA_DB_MAX_EMAIL_LENGTH', 80); @define('QA_DB_MAX_EMAIL_LENGTH', 80);
@define('QA_DB_MAX_HANDLE_LENGTH', 20); @define('QA_DB_MAX_HANDLE_LENGTH', 20);
@define('QA_DB_MAX_TITLE_LENGTH', 800); @define('QA_DB_MAX_TITLE_LENGTH', 800);
@define('QA_DB_MAX_CONTENT_LENGTH', 12000); @define('QA_DB_MAX_CONTENT_LENGTH', 12000);
@define('QA_DB_MAX_FORMAT_LENGTH', 20); @define('QA_DB_MAX_FORMAT_LENGTH', 20);
@define('QA_DB_MAX_TAGS_LENGTH', 800); @define('QA_DB_MAX_TAGS_LENGTH', 800);
@define('QA_DB_MAX_NAME_LENGTH', 40); @define('QA_DB_MAX_NAME_LENGTH', 40);
@define('QA_DB_MAX_WORD_LENGTH', 80); @define('QA_DB_MAX_WORD_LENGTH', 80);
@define('QA_DB_MAX_CAT_PAGE_TITLE_LENGTH', 80); @define('QA_DB_MAX_CAT_PAGE_TITLE_LENGTH', 80);
@define('QA_DB_MAX_CAT_PAGE_TAGS_LENGTH', 200); @define('QA_DB_MAX_CAT_PAGE_TAGS_LENGTH', 200);
@define('QA_DB_MAX_CAT_CONTENT_LENGTH', 800); @define('QA_DB_MAX_CAT_CONTENT_LENGTH', 800);
@define('QA_DB_MAX_WIDGET_TAGS_LENGTH', 800); @define('QA_DB_MAX_WIDGET_TAGS_LENGTH', 800);
@define('QA_DB_MAX_WIDGET_TITLE_LENGTH', 80); @define('QA_DB_MAX_WIDGET_TITLE_LENGTH', 80);
@define('QA_DB_MAX_OPTION_TITLE_LENGTH', 40); @define('QA_DB_MAX_OPTION_TITLE_LENGTH', 40);
@define('QA_DB_MAX_PROFILE_TITLE_LENGTH', 40); @define('QA_DB_MAX_PROFILE_TITLE_LENGTH', 40);
@define('QA_DB_MAX_PROFILE_CONTENT_LENGTH', 8000); @define('QA_DB_MAX_PROFILE_CONTENT_LENGTH', 8000);
@define('QA_DB_MAX_CACHE_AGE', 86400); @define('QA_DB_MAX_CACHE_AGE', 86400);
@define('QA_DB_MAX_BLOB_FILE_NAME_LENGTH', 255); @define('QA_DB_MAX_BLOB_FILE_NAME_LENGTH', 255);
@define('QA_DB_MAX_META_TITLE_LENGTH', 40); @define('QA_DB_MAX_META_TITLE_LENGTH', 40);
@define('QA_DB_MAX_META_CONTENT_LENGTH', 8000); @define('QA_DB_MAX_META_CONTENT_LENGTH', 8000);
// How many records to retrieve for different circumstances. In many cases we retrieve more records than we // How many records to retrieve for different circumstances. In many cases we retrieve more records than we
// end up needing to display once we know the value of an option. Wasteful, but allows one query per page. // end up needing to display once we know the value of an option. Wasteful, but allows one query per page.
@define('QA_DB_RETRIEVE_QS_AS', 50); @define('QA_DB_RETRIEVE_QS_AS', 50);
@define('QA_DB_RETRIEVE_TAGS', 200); @define('QA_DB_RETRIEVE_TAGS', 200);
@define('QA_DB_RETRIEVE_USERS', 200); @define('QA_DB_RETRIEVE_USERS', 200);
@define('QA_DB_RETRIEVE_ASK_TAG_QS', 500); @define('QA_DB_RETRIEVE_ASK_TAG_QS', 500);
@define('QA_DB_RETRIEVE_COMPLETE_TAGS', 1000); @define('QA_DB_RETRIEVE_COMPLETE_TAGS', 1000);
@define('QA_DB_RETRIEVE_MESSAGES', 20); @define('QA_DB_RETRIEVE_MESSAGES', 20);
// Keep event streams trimmed - not worth storing too many events per question because we only display the // Keep event streams trimmed - not worth storing too many events per question because we only display the
// most recent event for each question, that has not been invalidated due to hiding/unselection/etc... // most recent event for each question, that has not been invalidated due to hiding/unselection/etc...
@define('QA_DB_MAX_EVENTS_PER_Q', 5); @define('QA_DB_MAX_EVENTS_PER_Q', 5);
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -20,69 +20,76 @@ ...@@ -20,69 +20,76 @@
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_db_message_create($fromuserid, $touserid, $content, $format, $public=false) /**
/* * Record a message sent from $fromuserid to $touserid with $content in $format in the database. $public sets whether
Record a message sent from $fromuserid to $touserid with $content in $format in the database. $public sets whether * public (on wall) or private. Return the messageid of the row created.
public (on wall) or private. Return the messageid of the row created. * @param $fromuserid
*/ * @param $touserid
{ * @param $content
qa_db_query_sub( * @param $format
'INSERT INTO ^messages (type, fromuserid, touserid, content, format, created) VALUES ($, #, #, $, $, NOW())', * @param bool $public
$public ? 'PUBLIC' : 'PRIVATE', $fromuserid, $touserid, $content, $format * @return mixed
); */
function qa_db_message_create($fromuserid, $touserid, $content, $format, $public = false)
return qa_db_last_insert_id(); {
} qa_db_query_sub(
'INSERT INTO ^messages (type, fromuserid, touserid, content, format, created) VALUES ($, #, #, $, $, NOW())',
$public ? 'PUBLIC' : 'PRIVATE', $fromuserid, $touserid, $content, $format
function qa_db_message_user_hide($messageid, $box) );
/*
Hide the message with $messageid, in $box (inbox|outbox) from the user. return qa_db_last_insert_id();
*/ }
{
$field = ($box === 'inbox' ? 'tohidden' : 'fromhidden');
/**
qa_db_query_sub( * Hide the message with $messageid, in $box (inbox|outbox) from the user.
"UPDATE ^messages SET $field=1 WHERE messageid=#", * @param $messageid
$messageid * @param $box
); */
} function qa_db_message_user_hide($messageid, $box)
{
$field = ($box === 'inbox' ? 'tohidden' : 'fromhidden');
function qa_db_message_delete($messageid, $public=true)
/* qa_db_query_sub(
Delete the message with $messageid from the database. "UPDATE ^messages SET $field=1 WHERE messageid=#",
*/ $messageid
{ );
// delete PM only if both sender and receiver have hidden it }
$clause = $public ? '' : ' AND fromhidden=1 AND tohidden=1';
/**
* Delete the message with $messageid from the database.
* @param $messageid
* @param bool $public
*/
function qa_db_message_delete($messageid, $public = true)
{
// delete PM only if both sender and receiver have hidden it
$clause = $public ? '' : ' AND fromhidden=1 AND tohidden=1';
qa_db_query_sub(
'DELETE FROM ^messages WHERE messageid=#' . $clause,
$messageid
);
}
/**
* Recalculate the cached count of wall posts for user $userid in the database
* @param $userid
*/
function qa_db_user_recount_posts($userid)
{
if (qa_should_update_counts()) {
qa_db_query_sub( qa_db_query_sub(
'DELETE FROM ^messages WHERE messageid=#'.$clause, "UPDATE ^users AS x, (SELECT COUNT(*) AS wallposts FROM ^messages WHERE touserid=# AND type='PUBLIC') AS a SET x.wallposts=a.wallposts WHERE x.userid=#",
$messageid $userid, $userid
); );
} }
}
function qa_db_user_recount_posts($userid)
/*
Recalculate the cached count of wall posts for user $userid in the database
*/
{
if (qa_should_update_counts())
qa_db_query_sub(
"UPDATE ^users AS x, (SELECT COUNT(*) AS wallposts FROM ^messages WHERE touserid=# AND type='PUBLIC') AS a SET x.wallposts=a.wallposts WHERE x.userid=#",
$userid, $userid
);
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -20,179 +20,223 @@ ...@@ -20,179 +20,223 @@
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_db_usermeta_set($userid, $key, $value) /**
/* * Set the metadata for user $userid with $key to $value. Keys beginning qa_ are reserved for the Q2A core.
Set the metadata for user $userid with $key to $value. Keys beginning qa_ are reserved for the Q2A core. * @param $userid
*/ * @param $key
{ * @param $value
qa_db_meta_set('usermetas', 'userid', $userid, $key, $value); */
} function qa_db_usermeta_set($userid, $key, $value)
{
qa_db_meta_set('usermetas', 'userid', $userid, $key, $value);
function qa_db_usermeta_clear($userid, $key) }
/*
Clear the metadata for user $userid with $key ($key can also be an array of keys)
*/ /**
{ * Clear the metadata for user $userid with $key ($key can also be an array of keys)
qa_db_meta_clear('usermetas', 'userid', $userid, $key); * @param $userid
} * @param $key
*/
function qa_db_usermeta_clear($userid, $key)
function qa_db_usermeta_get($userid, $key) {
/* qa_db_meta_clear('usermetas', 'userid', $userid, $key);
Return the metadata value for user $userid with $key ($key can also be an array of keys in which case this }
returns an array of metadata key => value).
*/
{ /**
return qa_db_meta_get('usermetas', 'userid', $userid, $key); * Return the metadata value for user $userid with $key ($key can also be an array of keys in which case this
} * returns an array of metadata key => value).
* @param $userid
* @param $key
function qa_db_postmeta_set($postid, $key, $value) * @return array|mixed|null
/* */
Set the metadata for post $postid with $key to $value. Keys beginning qa_ are reserved for the Q2A core. function qa_db_usermeta_get($userid, $key)
*/ {
{ return qa_db_meta_get('usermetas', 'userid', $userid, $key);
qa_db_meta_set('postmetas', 'postid', $postid, $key, $value); }
}
/**
function qa_db_postmeta_clear($postid, $key) * Set the metadata for post $postid with $key to $value. Keys beginning qa_ are reserved for the Q2A core.
/* * @param $postid
Clear the metadata for post $postid with $key ($key can also be an array of keys) * @param $key
*/ * @param $value
{ */
qa_db_meta_clear('postmetas', 'postid', $postid, $key); function qa_db_postmeta_set($postid, $key, $value)
} {
qa_db_meta_set('postmetas', 'postid', $postid, $key, $value);
}
function qa_db_postmeta_get($postid, $key)
/*
Return the metadata value for post $postid with $key ($key can also be an array of keys in which case this /**
returns an array of metadata key => value). * Clear the metadata for post $postid with $key ($key can also be an array of keys)
*/ * @param $postid
{ * @param $key
return qa_db_meta_get('postmetas', 'postid', $postid, $key); */
} function qa_db_postmeta_clear($postid, $key)
{
qa_db_meta_clear('postmetas', 'postid', $postid, $key);
function qa_db_categorymeta_set($categoryid, $key, $value) }
/*
Set the metadata for category $categoryid with $key to $value. Keys beginning qa_ are reserved for the Q2A core.
*/ /**
{ * Return the metadata value for post $postid with $key ($key can also be an array of keys in which case this
qa_db_meta_set('categorymetas', 'categoryid', $categoryid, $key, $value); * returns an array of metadata key => value).
} * @param $postid
* @param $key
* @return array|mixed|null
function qa_db_categorymeta_clear($categoryid, $key) */
/* function qa_db_postmeta_get($postid, $key)
Clear the metadata for category $categoryid with $key ($key can also be an array of keys) {
*/ return qa_db_meta_get('postmetas', 'postid', $postid, $key);
{ }
qa_db_meta_clear('categorymetas', 'categoryid', $categoryid, $key);
}
/**
* Set the metadata for category $categoryid with $key to $value. Keys beginning qa_ are reserved for the Q2A core.
function qa_db_categorymeta_get($categoryid, $key) * @param $categoryid
/* * @param $key
Return the metadata value for category $categoryid with $key ($key can also be an array of keys in which * @param $value
case this returns an array of metadata key => value). */
*/ function qa_db_categorymeta_set($categoryid, $key, $value)
{ {
return qa_db_meta_get('categorymetas', 'categoryid', $categoryid, $key); qa_db_meta_set('categorymetas', 'categoryid', $categoryid, $key, $value);
} }
function qa_db_tagmeta_set($tag, $key, $value) /**
/* * Clear the metadata for category $categoryid with $key ($key can also be an array of keys)
Set the metadata for tag $tag with $key to $value. Keys beginning qa_ are reserved for the Q2A core. * @param $categoryid
*/ * @param $key
{ */
qa_db_meta_set('tagmetas', 'tag', $tag, $key, $value); function qa_db_categorymeta_clear($categoryid, $key)
} {
qa_db_meta_clear('categorymetas', 'categoryid', $categoryid, $key);
}
function qa_db_tagmeta_clear($tag, $key)
/*
Clear the metadata for tag $tag with $key ($key can also be an array of keys) /**
*/ * Return the metadata value for category $categoryid with $key ($key can also be an array of keys in which
{ * case this returns an array of metadata key => value).
qa_db_meta_clear('tagmetas', 'tag', $tag, $key); * @param $categoryid
} * @param $key
* @return array|mixed|null
*/
function qa_db_tagmeta_get($tag, $key) function qa_db_categorymeta_get($categoryid, $key)
/* {
Return the metadata value for tag $tag with $key ($key can also be an array of keys in which case this return qa_db_meta_get('categorymetas', 'categoryid', $categoryid, $key);
returns an array of metadata key => value). }
*/
{
return qa_db_meta_get('tagmetas', 'tag', $tag, $key); /**
} * Set the metadata for tag $tag with $key to $value. Keys beginning qa_ are reserved for the Q2A core.
* @param $tag
* @param $key
function qa_db_meta_set($metatable, $idcolumn, $idvalue, $title, $content) * @param $value
/* */
Internal general function to set metadata function qa_db_tagmeta_set($tag, $key, $value)
*/ {
{ qa_db_meta_set('tagmetas', 'tag', $tag, $key, $value);
qa_db_query_sub( }
'INSERT INTO ^' . $metatable . ' (' . $idcolumn . ', title, content) VALUES ($, $, $) ' .
'ON DUPLICATE KEY UPDATE content = VALUES(content)',
$idvalue, $title, $content /**
); * Clear the metadata for tag $tag with $key ($key can also be an array of keys)
} * @param $tag
* @param $key
*/
function qa_db_meta_clear($metatable, $idcolumn, $idvalue, $title) function qa_db_tagmeta_clear($tag, $key)
/* {
Internal general function to clear metadata qa_db_meta_clear('tagmetas', 'tag', $tag, $key);
*/ }
{
if (is_array($title)) {
if (count($title)) /**
qa_db_query_sub( * Return the metadata value for tag $tag with $key ($key can also be an array of keys in which case this
'DELETE FROM ^'.$metatable.' WHERE '.$idcolumn.'=$ AND title IN ($)', * returns an array of metadata key => value).
$idvalue, $title * @param $tag
); * @param $key
* @return array|mixed|null
} else */
function qa_db_tagmeta_get($tag, $key)
{
return qa_db_meta_get('tagmetas', 'tag', $tag, $key);
}
/**
* Internal general function to set metadata
* @param $metatable
* @param $idcolumn
* @param $idvalue
* @param $title
* @param $content
*/
function qa_db_meta_set($metatable, $idcolumn, $idvalue, $title, $content)
{
qa_db_query_sub(
'INSERT INTO ^' . $metatable . ' (' . $idcolumn . ', title, content) VALUES ($, $, $) ' .
'ON DUPLICATE KEY UPDATE content = VALUES(content)',
$idvalue, $title, $content
);
}
/**
* Internal general function to clear metadata
* @param $metatable
* @param $idcolumn
* @param $idvalue
* @param $title
*/
function qa_db_meta_clear($metatable, $idcolumn, $idvalue, $title)
{
if (is_array($title)) {
if (count($title)) {
qa_db_query_sub( qa_db_query_sub(
'DELETE FROM ^'.$metatable.' WHERE '.$idcolumn.'=$ AND title=$', 'DELETE FROM ^' . $metatable . ' WHERE ' . $idcolumn . '=$ AND title IN ($)',
$idvalue, $title $idvalue, $title
); );
}
} else {
qa_db_query_sub(
'DELETE FROM ^' . $metatable . ' WHERE ' . $idcolumn . '=$ AND title=$',
$idvalue, $title
);
} }
}
function qa_db_meta_get($metatable, $idcolumn, $idvalue, $title)
/* /**
Internal general function to return metadata * Internal general function to return metadata
*/ * @param $metatable
{ * @param $idcolumn
if (is_array($title)) { * @param $idvalue
if (count($title)) * @param $title
return qa_db_read_all_assoc(qa_db_query_sub( * @return array|mixed|null
'SELECT title, content FROM ^'.$metatable.' WHERE '.$idcolumn.'=$ AND title IN($)', */
$idvalue, $title function qa_db_meta_get($metatable, $idcolumn, $idvalue, $title)
), 'title', 'content'); {
else if (is_array($title)) {
return array(); if (count($title)) {
return qa_db_read_all_assoc(qa_db_query_sub(
} else 'SELECT title, content FROM ^' . $metatable . ' WHERE ' . $idcolumn . '=$ AND title IN($)',
return qa_db_read_one_value(qa_db_query_sub(
'SELECT content FROM ^'.$metatable.' WHERE '.$idcolumn.'=$ AND title=$',
$idvalue, $title $idvalue, $title
), true); ), 'title', 'content');
} } else {
return array();
}
/*
Omit PHP closing tag to help avoid accidental output } else {
*/ return qa_db_read_one_value(qa_db_query_sub(
\ No newline at end of file 'SELECT content FROM ^' . $metatable . ' WHERE ' . $idcolumn . '=$ AND title=$',
$idvalue, $title
), true);
}
}
...@@ -20,50 +20,54 @@ ...@@ -20,50 +20,54 @@
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_db_usernotice_create($userid, $content, $format='', $tags=null) /**
/* * Create a notice for $userid with $content in $format and optional $tags (not displayed) and return its noticeid
Create a notice for $userid with $content in $format and optional $tags (not displayed) and return its noticeid * @param $userid
*/ * @param $content
{ * @param string $format
qa_db_query_sub( * @param $tags
'INSERT INTO ^usernotices (userid, content, format, tags, created) VALUES ($, $, $, $, NOW())', * @return mixed
$userid, $content, $format, $tags */
); function qa_db_usernotice_create($userid, $content, $format = '', $tags = null)
{
qa_db_query_sub(
'INSERT INTO ^usernotices (userid, content, format, tags, created) VALUES ($, $, $, $, NOW())',
$userid, $content, $format, $tags
);
return qa_db_last_insert_id(); return qa_db_last_insert_id();
} }
function qa_db_usernotice_delete($userid, $noticeid) /**
/* * Delete the notice $notice which belongs to $userid
Delete the notice $notice which belongs to $userid * @param $userid
*/ * @param $noticeid
{ */
qa_db_query_sub( function qa_db_usernotice_delete($userid, $noticeid)
'DELETE FROM ^usernotices WHERE userid=$ AND noticeid=#', {
$userid, $noticeid qa_db_query_sub(
); 'DELETE FROM ^usernotices WHERE userid=$ AND noticeid=#',
} $userid, $noticeid
);
}
function qa_db_usernotices_list($userid) /**
/* * Return an array summarizing the notices to be displayed for $userid, including the tags (not displayed)
Return an array summarizing the notices to be displayed for $userid, including the tags (not displayed) * @param $userid
*/ * @return array
{ */
return qa_db_read_all_assoc(qa_db_query_sub( function qa_db_usernotices_list($userid)
'SELECT noticeid, tags, UNIX_TIMESTAMP(created) AS created FROM ^usernotices WHERE userid=$ ORDER BY created', {
$userid return qa_db_read_all_assoc(qa_db_query_sub(
)); 'SELECT noticeid, tags, UNIX_TIMESTAMP(created) AS created FROM ^usernotices WHERE userid=$ ORDER BY created',
} $userid
));
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -20,25 +20,22 @@ ...@@ -20,25 +20,22 @@
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_db_set_option($name, $value) /**
/* * Set option $name to $value in the database
Set option $name to $value in the database * @param $name
*/ * @param $value
{ */
qa_db_query_sub( function qa_db_set_option($name, $value)
'INSERT INTO ^options (title, content) VALUES ($, $) ' . {
'ON DUPLICATE KEY UPDATE content = VALUES(content)', qa_db_query_sub(
$name, $value 'INSERT INTO ^options (title, content) VALUES ($, $) ' .
); 'ON DUPLICATE KEY UPDATE content = VALUES(content)',
} $name, $value
);
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
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