예제 #1
0
function new_channel_init(&$a)
{
    $cmd = argc() > 1 ? argv(1) : '';
    if ($cmd === 'autofill.json') {
        require_once 'library/urlify/URLify.php';
        $result = array('error' => false, 'message' => '');
        $n = trim($_REQUEST['name']);
        $x = strtolower(URLify::transliterate($n));
        $test = array();
        // first name
        if (strpos($x, ' ')) {
            $test[] = legal_webbie(substr($x, 0, strpos($x, ' ')));
        }
        if ($test[0]) {
            // first name plus first initial of last
            $test[] = strpos($x, ' ') ? $test[0] . legal_webbie(trim(substr($x, strpos($x, ' '), 2))) : '';
            // first name plus random number
            $test[] = $test[0] . mt_rand(1000, 9999);
        }
        // fullname
        $test[] = legal_webbie($x);
        // fullname plus random number
        $test[] = legal_webbie($x) . mt_rand(1000, 9999);
        json_return_and_die(check_webbie($test));
    }
    if ($cmd === 'checkaddr.json') {
        require_once 'library/urlify/URLify.php';
        $result = array('error' => false, 'message' => '');
        $n = trim($_REQUEST['nick']);
        $x = strtolower(URLify::transliterate($n));
        $test = array();
        $n = legal_webbie($x);
        if (strlen($n)) {
            $test[] = $n;
            $test[] = $n . mt_rand(1000, 9999);
        }
        for ($y = 0; $y < 100; $y++) {
            $test[] = 'id' . mt_rand(1000, 9999);
        }
        json_return_and_die(check_webbie($test));
    }
}
예제 #2
0
function auto_channel_create($account_id)
{
    if (!$account_id) {
        return false;
    }
    $arr = array();
    $arr['account_id'] = $account_id;
    $arr['name'] = get_aconfig($account_id, 'register', 'channel_name');
    $arr['nickname'] = legal_webbie(get_aconfig($account_id, 'register', 'channel_address'));
    $arr['permissions_role'] = get_aconfig($account_id, 'register', 'permissions_role');
    del_aconfig($account_id, 'register', 'channel_name');
    del_aconfig($account_id, 'register', 'channel_address');
    del_aconfig($account_id, 'register', 'permissions_role');
    if (!$arr['name'] || !$arr['nickname']) {
        $x = q("select * from account where account_id = %d limit 1", intval($account_id));
        if ($x) {
            if (!$arr['name']) {
                $arr['name'] = substr($x[0]['account_email'], 0, strpos($x[0]['account_email'], '@'));
            }
            if (!$arr['nickname']) {
                $arr['nickname'] = legal_webbie(substr($x[0]['account_email'], 0, strpos($x[0]['account_email'], '@')));
            }
        }
    }
    if (!$arr['permissions_role']) {
        $arr['permissions_role'] = 'social';
    }
    if (validate_channelname($arr['name'])) {
        return false;
    }
    if ($arr['nickname'] === 'sys') {
        $arr['nickname'] = $arr['nickname'] . mt_rand(1000, 9999);
    }
    $arr['nickname'] = check_webbie(array($arr['nickname'], $arr['nickname'] . mt_rand(1000, 9999)));
    return create_identity($arr);
}
예제 #3
0
파일: text.php 프로젝트: 23n/hubzilla
function check_webbie($arr)
{
    $reservechan = get_config('system', 'reserved_channels');
    if (strlen($reservechan)) {
        $taken = explode(',', $reservechan);
    } else {
        $taken = array();
    }
    $str = '';
    if (count($arr)) {
        foreach ($arr as $x) {
            $y = legal_webbie($x);
            if (strlen($y)) {
                if ($str) {
                    $str .= ',';
                }
                $str .= "'" . dbesc($y) . "'";
            }
        }
        if (strlen($str)) {
            $r = q("select channel_address from channel where channel_address in ( {$str} ) ");
            if (count($r)) {
                foreach ($r as $rr) {
                    $taken[] = $rr['channel_address'];
                }
            }
            foreach ($arr as $x) {
                $y = legal_webbie($x);
                if (!in_array($y, $taken)) {
                    return $y;
                }
            }
        }
    }
    return '';
}
예제 #4
0
파일: text.php 프로젝트: Mauru/red
function check_webbie($arr)
{
    $str = '';
    $taken = array();
    if (count($arr)) {
        foreach ($arr as $x) {
            $y = legal_webbie($x);
            if (strlen($y)) {
                if ($str) {
                    $str .= ',';
                }
                $str .= "'" . dbesc($y) . "'";
            }
        }
        if (strlen($str)) {
            $r = q("select channel_address from channel where channel_address in ( {$str} ) ");
            if (count($r)) {
                foreach ($r as $rr) {
                    $taken[] = $rr['channel_address'];
                }
            }
            foreach ($arr as $x) {
                $y = legal_webbie($x);
                if (!in_array($y, $taken)) {
                    return $y;
                }
            }
        }
    }
    return '';
}