3.0.1). */
function nntp_tracker($flds)
{
$c = q('SELECT id, server, newsgroup FROM '. $GLOBALS['DBHOST_TBL_PREFIX'] .'nntp');
while ($r = db_rowarr($c)) {
if (@file_exists($GLOBALS['ERROR_PATH'] .'.nntp/'. $r[1] .'-'. $r[2])) {
$tracker = (int) trim(file_get_contents($GLOBALS['ERROR_PATH'] .'.nntp/'. $r[1] .'-'. $r[2]));
q('UPDATE '. $GLOBALS['DBHOST_TBL_PREFIX'] .'nntp SET tracker='. $tracker .' WHERE id='. $r[0]);
pf('Tracker for NNTP server '. $r[1] .', group '. $r[2] .' was moved into the DB.');
@unlink($GLOBALS['ERROR_PATH'] .'.nntp/'. $r[1] .'-'. $r[2]);
} else {
pf('Unable to move tracker for NNTP server '. $r[1] .', group '. $r[2] .' into the DB.');
}
}
}
/** Change birthday from NUMBER to CHAR(8) (3.0.1->3.0.2).
* New format is MMDDYYYY.
* Required for index lookups on leading string. I.e: WHERE birthday LIKE 'mmdd%';
*/
function users_birthday($flds)
{
pf('About to change birthday format. This may take a while...');
$c = q('SELECT id, bday FROM '. $GLOBALS['DBHOST_TBL_PREFIX'] .'users');
while ($r = db_rowarr($c)) {
$bday = $yyyy = $mm = $dd = null;
$bday = str_pad($r[1], 8, '0', STR_PAD_LEFT);
$yyyy = substr($bday, 0, 4);
$mm = substr($bday, 4, 2);
$dd = substr($bday, 6, 2);
$yyyy = ($yyyy == '0000') ? ' ' : $yyyy;
$mm = ($mm == '00') ? ' ' : $mm;
$dd = ($dd == '00') ? ' ' : $dd;
q('UPDATE '. $GLOBALS['DBHOST_TBL_PREFIX'] .'users SET birthday=\''. $mm . $dd . $yyyy .'\' WHERE id='. $r[0]);
}
pf('Birthday format change completed.');
}
/** Change reg_ip (encoded IPv4 address) to registration_ip (IPv6 address) (3.0.4RC2 -> 3.0.4RC3). */
function users_reg_ip($flds)
{
pf('Convert reg_ip to registration_ip for IPv6 compatibility');
try {
$c = q('SELECT id, reg_ip FROM '. $GLOBALS['DBHOST_TBL_PREFIX'] .'users');
while ($r = db_rowarr($c)) {
q('UPDATE '. $GLOBALS['DBHOST_TBL_PREFIX'] .'users SET registration_ip=\''. long2ip($r[1]) .'\' WHERE id='. $r[0]);
}
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
}
/** Change last_known_ip (encoded IPv4 address) to last_used_ip (IPv6 address) (3.0.4RC2 -> 3.0.4RC3). */
function users_last_known_ip($flds)
{
pf('Convert last_known_ip to last_used_ip IPv6 compatibility');
try {
$c = q('SELECT id, last_known_ip FROM '. $GLOBALS['DBHOST_TBL_PREFIX'] .'users');
while ($r = db_rowarr($c)) {
q('UPDATE '. $GLOBALS['DBHOST_TBL_PREFIX'] .'users SET last_used_ip=\''. long2ip($r[1]) .'\' WHERE id='. $r[0]);
}
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
}
/** Change reset/conf_key from '0' (VARCHAR) to NULL (no need to store & index a bunch of 0 values). */
function users_conf_key($flds)
{
pf('Convert reset_key & conf_key from 0 to NULL');
q('UPDATE '. $GLOBALS['DBHOST_TBL_PREFIX'] .'users SET conf_key =NULL WHERE conf_key =\'0\'');
q('UPDATE '. $GLOBALS['DBHOST_TBL_PREFIX'] .'users SET reset_key=NULL WHERE reset_key=\'0\'');
}
function users_reset_key($flds)
{
users_conf_key($flds);
}
/* For future implementation -
// Convert 'location' to a Custom Profile Field.
function users_location($flds)
{
fud_use('custom_field_adm.inc', true);
$cfield = new fud_custom_field;
$cfield->name = 'Location';
$cfield->descr = NULL;
$cfield->type_opt = 0; // Single line.
$cfield->choice = NULL;
$cfield->vieworder = NULL;
$cfield->field_opt = 2; // Optional, only user can edit, everyone can see value.
$locid = $cfield->add();
$c = q('SELECT id, custom_fields, location FROM '. $GLOBALS['DBHOST_TBL_PREFIX'] .'users WHERE location IS NOT NULL and location <> \'\'');
while ($r = db_rowarr($c)) {
$x = isset($r[1]) ? unserialize($r[1]) : array();
$x[$locid] = $r[2];
q('UPDATE '. $GLOBALS['DBHOST_TBL_PREFIX'] .'users SET custom_fields = '. _esc(serialize($x)) .' WHERE id = '. $r[0]);
}
}
*/
/* END: SQL Upgrade Functions */
function fud_ini_get($opt)
{
return (ini_get($opt) == '1' ? 1 : 0);
}
function fud_ini_set($opt, $val)
{
if (function_exists('ini_set')) {
ini_set($opt, $val);
}
}
/** Print message to web browser or command line. */
function pf($msg='', $webonly=false)
{
if (php_sapi_name() == 'cli') {
if ($webonly) return;
echo strip_tags($msg) ."\n";
} else {
echo $msg . (stripos($msg, '