aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/account.php96
-rw-r--r--include/channel.php2
-rw-r--r--include/hubloc.php30
-rw-r--r--include/menu.php24
4 files changed, 77 insertions, 75 deletions
diff --git a/include/account.php b/include/account.php
index 4c5437594..d138dab41 100644
--- a/include/account.php
+++ b/include/account.php
@@ -34,23 +34,29 @@ function check_account_email($email) {
if(! strlen($email))
return $result;
- if(! validate_email($email))
- $result['message'] = t('The provided email address is not valid') . EOL;
- elseif(! allowed_email($email))
+ if(! validate_email($email)) {
+ $result['message'] = t('The provided email address is not valid');
+ }
+ elseif(! allowed_email($email)) {
$result['message'] = t('The provided email domain is not among those allowed on this site');
+ }
else {
- $r = q("select account_email from account where account_email = '%s' limit 1",
+ $account = q("select account_email from account where account_email = '%s' limit 1",
dbesc($email)
);
- if (!$r) {
- $r = q("select reg_did2 from register where reg_did2 = '%s' limit 1",
- dbesc($email)
- );
- }
- if($r) {
+ if ($account) {
$result['message'] = t('The provided email address is already registered at this site');
}
+
+ $register = q("select reg_did2 from register where reg_vital = 1 and reg_did2 = '%s' limit 1",
+ dbesc($email)
+ );
+ if ($register) {
+ $result['message'] = t('There is a pending registration for this address - click "Register" to continue verification');
+ $result['email_unverified'] = true;
+ }
}
+
if($result['message'])
$result['error'] = true;
@@ -856,12 +862,12 @@ function verify_register_scheme() {
if ($dbc[0]=='id') {
// v1 format
- q("START TRANSACTION");
+ dbq("START TRANSACTION");
if(ACTIVE_DBTYPE == DBTYPE_POSTGRES) {
- $r1 = q("ALTER TABLE register RENAME TO register100;");
+ $r1 = dbq("ALTER TABLE register RENAME TO register100;");
- $r2 = q("CREATE TABLE register ("
+ $r2 = dbq("CREATE TABLE register ("
. "reg_id serial NOT NULL,"
. "reg_vital int DEFAULT 1 NOT NULL,"
. "reg_flags bigint DEFAULT 0 NOT NULL,"
@@ -869,9 +875,9 @@ function verify_register_scheme() {
. "reg_did2 text DEFAULT '' NOT NULL,"
. "reg_hash text DEFAULT '' NOT NULL,"
. "reg_email text DEFAULT '' NOT NULL,"
- . "reg_created timestamp NOT NULL,"
- . "reg_startup timestamp NOT NULL,"
- . "reg_expires timestamp NOT NULL,"
+ . "reg_created timestamp NOT NULL DEFAULT '0001-01-01 00:00:00',"
+ . "reg_startup timestamp NOT NULL DEFAULT '0001-01-01 00:00:00',"
+ . "reg_expires timestamp NOT NULL DEFAULT '0001-01-01 00:00:00',"
. "reg_byc bigint DEFAULT 0 NOT NULL,"
. "reg_uid bigint DEFAULT 0 NOT NULL,"
. "reg_atip text DEFAULT '' NOT NULL,"
@@ -880,29 +886,29 @@ function verify_register_scheme() {
. "reg_stuff text NOT NULL,"
. "PRIMARY KEY (reg_id) );"
);
- $r0 = q("CREATE INDEX ix_reg_vital ON register (reg_vital);");
- $r0 = q("CREATE INDEX ix_reg_flags ON register (reg_flags);");
- $r0 = q("CREATE INDEX ix_reg_didx ON register (reg_didx);");
- $r0 = q("CREATE INDEX ix_reg_did2 ON register (reg_did2);");
- $r0 = q("CREATE INDEX ix_reg_hash ON register (reg_hash);");
- $r0 = q("CREATE INDEX ix_reg_email ON register (reg_email);");
- $r0 = q("CREATE INDEX ix_reg_created ON register (reg_created);");
- $r0 = q("CREATE INDEX ix_reg_startup ON register (reg_startup);");
- $r0 = q("CREATE INDEX ix_reg_expires ON register (reg_expires);");
- $r0 = q("CREATE INDEX ix_reg_byc ON register (reg_byc);");
- $r0 = q("CREATE INDEX ix_reg_uid ON register (reg_uid);");
- $r0 = q("CREATE INDEX ix_reg_atip ON register (reg_atip);");
-
- $r3 = q("INSERT INTO register (reg_id, reg_hash, reg_created, reg_uid, reg_pass, reg_lang, reg_stuff) "
+ $r0 = dbq("CREATE INDEX ix_reg_vital ON register (reg_vital);");
+ $r0 = dbq("CREATE INDEX ix_reg_flags ON register (reg_flags);");
+ $r0 = dbq("CREATE INDEX ix_reg_didx ON register (reg_didx);");
+ $r0 = dbq("CREATE INDEX ix_reg_did2 ON register (reg_did2);");
+ $r0 = dbq("CREATE INDEX ix_reg_hash ON register (reg_hash);");
+ $r0 = dbq("CREATE INDEX ix_reg_email ON register (reg_email);");
+ $r0 = dbq("CREATE INDEX ix_reg_created ON register (reg_created);");
+ $r0 = dbq("CREATE INDEX ix_reg_startup ON register (reg_startup);");
+ $r0 = dbq("CREATE INDEX ix_reg_expires ON register (reg_expires);");
+ $r0 = dbq("CREATE INDEX ix_reg_byc ON register (reg_byc);");
+ $r0 = dbq("CREATE INDEX ix_reg_uid ON register (reg_uid);");
+ $r0 = dbq("CREATE INDEX ix_reg_atip ON register (reg_atip);");
+
+ $r3 = dbq("INSERT INTO register (reg_id, reg_hash, reg_created, reg_uid, reg_pass, reg_lang, reg_stuff) "
. "SELECT id, hash, created, uid, password, lang, '' FROM register100;");
- $r4 = q("DROP TABLE register100");
+ $r4 = dbq("DROP TABLE register100");
}
else {
- $r1 = q("RENAME TABLE register TO register100;");
+ $r1 = dbq("RENAME TABLE register TO register100;");
- $r2 = q("CREATE TABLE IF NOT EXISTS register ("
+ $r2 = dbq("CREATE TABLE IF NOT EXISTS register ("
. "reg_id int(10) UNSIGNED NOT NULL AUTO_INCREMENT,"
. "reg_vital int(10) UNSIGNED NOT NULL DEFAULT 1,"
. "reg_flags int(10) UNSIGNED NOT NULL DEFAULT 0,"
@@ -935,10 +941,10 @@ function verify_register_scheme() {
. ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"
);
- $r3 = q("INSERT INTO register (reg_id, reg_hash, reg_created, reg_uid, reg_pass, reg_lang, reg_stuff) "
+ $r3 = dbq("INSERT INTO register (reg_id, reg_hash, reg_created, reg_uid, reg_pass, reg_lang, reg_stuff) "
. "SELECT id, hash, created, uid, password, lang, '' FROM register100;");
- $r4 = q("DROP TABLE register100");
+ $r4 = dbq("DROP TABLE register100");
}
// $r = ($r1 && $r2 && $r3 && $r4);
@@ -946,11 +952,11 @@ function verify_register_scheme() {
$r = $r2;
if($r) {
- q("COMMIT");
+ dbq("COMMIT");
return UPDATE_SUCCESS;
}
- q("ROLLBACK");
+ dbq("ROLLBACK");
return UPDATE_FAILED;
}
elseif ( count($dbc) != 16 ) {
@@ -1275,14 +1281,6 @@ function zar_register_dutystate( $now=NULL, $day=NULL ) {
function get_pending_accounts($get_all = false) {
- /* get pending */
- // [hilmar ->
- //~ $r = q("SELECT account.*, reg_hash FROM account LEFT JOIN register ON account_id = reg_uid WHERE reg_vital = 1 AND (account_flags & %d) > 0",
- //~ intval(ACCOUNT_PENDING)
- //~ );
-
- // better useability at the moment to tell all (ACCOUNT_PENDING >= 0) instead of (> 0 for those need approval)
-
$sql_extra = " AND (reg_flags & " . ACCOUNT_UNVERIFIED . ") = 0 ";
if($get_all)
@@ -1295,3 +1293,11 @@ function get_pending_accounts($get_all = false) {
return $r;
}
+
+function remove_expired_registrations() {
+ q("DELETE FROM register WHERE (reg_expires < '%s' OR reg_expires = '%s') AND (reg_flags & %d) > 0",
+ dbesc(datetime_convert()),
+ dbesc(NULL_DATE),
+ dbesc(ACCOUNT_UNVERIFIED)
+ );
+}
diff --git a/include/channel.php b/include/channel.php
index e636a22d6..804d8c63a 100644
--- a/include/channel.php
+++ b/include/channel.php
@@ -2596,7 +2596,7 @@ function channelx_by_n($id) {
}
$r = q("SELECT * FROM channel LEFT JOIN xchan ON channel_hash = xchan_hash WHERE channel_id = %d AND channel_removed = 0 LIMIT 1",
- dbesc($id)
+ intval($id)
);
return(($r) ? $r[0] : false);
diff --git a/include/hubloc.php b/include/hubloc.php
index 7af4e471b..2cce7a725 100644
--- a/include/hubloc.php
+++ b/include/hubloc.php
@@ -175,40 +175,36 @@ function remove_obsolete_hublocs() {
/**
* @brief Remove duplicate singleton hublocs
*
+ * This should not actually happen but it appears it does - probably due to race conditions.
* This function will just leave the hubloc with the highest id (latest)
*
+ * TODO: we should probably do something about that at the DB level.
+ *
*/
function remove_duplicate_singleton_hublocs() {
- $hublocs = dbq("SELECT
- hubloc_id_url,
- COUNT(hubloc_id_url)
- FROM
- hubloc
- WHERE
- hubloc_network IN (
+ $hublocs = dbq("SELECT hubloc_hash, COUNT(hubloc_hash) FROM hubloc WHERE
+ hubloc_network IN(
'activitypub',
'diaspora',
'friendica-over-diaspora',
'gnusoc'
)
- GROUP BY
- hubloc_id_url
- HAVING
- COUNT(hubloc_id_url) > 1"
+ GROUP BY hubloc_hash
+ HAVING COUNT(hubloc_hash) > 1"
);
foreach($hublocs as $hubloc) {
- $hubloc_id_url = $hubloc['hubloc_id_url'];
+ $hubloc_hash = $hubloc['hubloc_hash'];
- $max_id = q("select max(hubloc_id) as max_id from hubloc where hubloc_id_url = '%s'",
- dbesc($hubloc_id_url)
+ $max_id = q("select max(hubloc_id) as max_id from hubloc where hubloc_hash = '%s'",
+ dbesc($hubloc_hash)
);
$id = $max_id[0]['max_id'];
- if($hubloc_id_url && $id) {
- q("delete from hubloc where hubloc_id_url = '%s' and hubloc_id != %d",
- dbesc($hubloc_id_url),
+ if($hubloc_hash && $id) {
+ q("delete from hubloc where hubloc_hash = '%s' and hubloc_id != %d",
+ dbesc($hubloc_hash),
intval($id)
);
}
diff --git a/include/menu.php b/include/menu.php
index 02b05a36e..1f65f987d 100644
--- a/include/menu.php
+++ b/include/menu.php
@@ -16,7 +16,7 @@ function menu_fetch($name,$uid,$observer_xchan) {
);
if($r) {
$x = q("select * from menu_item where mitem_menu_id = %d and mitem_channel_id = %d
- $sql_options
+ $sql_options
order by mitem_order asc, mitem_desc asc",
intval($r[0]['menu_id']),
intval($uid)
@@ -26,7 +26,7 @@ function menu_fetch($name,$uid,$observer_xchan) {
return null;
}
-
+
function menu_element($channel,$menu) {
$arr = array();
@@ -67,7 +67,7 @@ function menu_element($channel,$menu) {
}
$arr['items'][] = $entry;
}
- }
+ }
return $arr;
}
@@ -111,7 +111,7 @@ function menu_render($menu, $class='', $edit = false, $var = array()) {
$menu['items'][$x]['mitem_desc'] = zidify_links(smilies(bbcode($menu['items'][$x]['mitem_desc'])));
}
- $wrap = (! x($var, 'wrap') || $var['wrap'] === 'none' ? false : true);
+ $wrap = ((isset($var['wrap']) && $var['wrap'] === 'none') ? false : true);
$ret = replace_macros(get_markup_template('usermenu.tpl'),array(
'$menu' => $menu['menu'],
@@ -168,7 +168,7 @@ function menu_create($arr) {
$t = datetime_convert();
- $r = q("insert into menu ( menu_name, menu_desc, menu_flags, menu_channel_id, menu_created, menu_edited )
+ $r = q("insert into menu ( menu_name, menu_desc, menu_flags, menu_channel_id, menu_created, menu_edited )
values( '%s', '%s', %d, %d, '%s', '%s' )",
dbesc($menu_name),
dbesc($menu_desc),
@@ -260,7 +260,7 @@ function menu_edit($arr) {
}
return q("update menu set menu_name = '%s', menu_desc = '%s', menu_flags = %d, menu_edited = '%s'
- where menu_id = %d and menu_channel_id = %d",
+ where menu_id = %d and menu_channel_id = %d",
dbesc($menu_name),
dbesc($menu_desc),
intval($menu_flags),
@@ -295,7 +295,7 @@ function menu_delete_id($menu_id, $uid) {
intval($menu_id),
intval($uid)
);
- }
+ }
return false;
}
@@ -304,11 +304,11 @@ function menu_add_item($menu_id, $uid, $arr) {
$mitem_link = escape_tags($arr['mitem_link']);
$mitem_desc = escape_tags($arr['mitem_desc']);
- $mitem_order = intval($arr['mitem_order']);
+ $mitem_order = intval($arr['mitem_order']);
$mitem_flags = intval($arr['mitem_flags']);
if(local_channel() == $uid) {
- $channel = App::get_channel();
+ $channel = App::get_channel();
}
$acl = new Zotlabs\Access\AccessList($channel);
@@ -344,12 +344,12 @@ function menu_edit_item($menu_id, $uid, $arr) {
$mitem_id = intval($arr['mitem_id']);
$mitem_link = escape_tags($arr['mitem_link']);
$mitem_desc = escape_tags($arr['mitem_desc']);
- $mitem_order = intval($arr['mitem_order']);
+ $mitem_order = intval($arr['mitem_order']);
$mitem_flags = intval($arr['mitem_flags']);
if(local_channel() == $uid) {
- $channel = App::get_channel();
+ $channel = App::get_channel();
}
$acl = new Zotlabs\Access\AccessList($channel);
@@ -403,7 +403,7 @@ function menu_sync_packet($uid,$observer_hash,$menu_id,$delete = false) {
$r = menu_fetch_id($menu_id,$uid);
$c = channelx_by_n($uid);
if($r) {
- $m = menu_fetch($r['menu_name'],$uid,$observer_hash);
+ $m = menu_fetch($r['menu_name'],$uid,$observer_hash);
if($m) {
if($delete)
$m['menu_delete'] = 1;