Esempio n. 1
0
function newNotice($i, $tagmax)
{
    global $userprefix;
    $options = array('scope' => Notice::defaultScope());
    $n = rand(0, $i - 1);
    $user = User::getKV('nickname', sprintf('%s%d', $userprefix, $n));
    $is_reply = rand(0, 1);
    $content = testNoticeContent();
    if ($is_reply == 0) {
        $stream = new InboxNoticeStream($user->getProfile(), $user->getProfile());
        $notices = $stream->getNotices(0, 20);
        if ($notices->N > 0) {
            $nval = rand(0, $notices->N - 1);
            $notices->fetch();
            // go to 0th
            for ($i = 0; $i < $nval; $i++) {
                $notices->fetch();
            }
            $options['reply_to'] = $notices->id;
            $dont_use_nickname = rand(0, 2);
            if ($dont_use_nickname != 0) {
                $rprofile = $notices->getProfile();
                $content = "@" . $rprofile->nickname . " " . $content;
            }
            $private_to_addressees = rand(0, 4);
            if ($private_to_addressees == 0) {
                $options['scope'] |= Notice::ADDRESSEE_SCOPE;
            }
        }
    } else {
        $is_directed = rand(0, 4);
        if ($is_directed == 0) {
            $subs = $user->getSubscribed(0, 100)->fetchAll();
            if (count($subs) > 0) {
                $seen = array();
                $f = rand(0, 9);
                if ($f <= 6) {
                    $addrs = 1;
                } else {
                    if ($f <= 8) {
                        $addrs = 2;
                    } else {
                        $addrs = 3;
                    }
                }
                for ($m = 0; $m < $addrs; $m++) {
                    $x = rand(0, count($subs) - 1);
                    if ($seen[$x]) {
                        continue;
                    }
                    if ($subs[$x]->id == $user->id) {
                        continue;
                    }
                    $seen[$x] = true;
                    $rprofile = $subs[$x];
                    $content = "@" . $rprofile->nickname . " " . $content;
                }
                $private_to_addressees = rand(0, 4);
                if ($private_to_addressees == 0) {
                    $options['scope'] |= Notice::ADDRESSEE_SCOPE;
                }
            }
        }
    }
    $has_hash = rand(0, 2);
    if ($has_hash == 0) {
        $hashcount = rand(0, 2);
        for ($j = 0; $j < $hashcount; $j++) {
            $h = rand(0, $tagmax);
            $content .= " #tag{$h}";
        }
    }
    $in_group = rand(0, 5);
    if ($in_group == 0) {
        $groups = $user->getGroups();
        if ($groups instanceof User_group) {
            $gval = rand(0, $groups->N - 1);
            $groups->fetch();
            // go to 0th
            for ($i = 0; $i < $gval; $i++) {
                $groups->fetch();
            }
            $options['groups'] = array($groups->id);
            $content = "!" . $groups->nickname . " " . $content;
            $private_to_group = rand(0, 2);
            if ($private_to_group == 0) {
                $options['scope'] |= Notice::GROUP_SCOPE;
            }
        }
    }
    $private_to_site = rand(0, 4);
    if ($private_to_site == 0) {
        $options['scope'] |= Notice::SITE_SCOPE;
    }
    $notice = Notice::saveNew($user->id, $content, 'createsim', $options);
}
Esempio n. 2
0
function newNotice($i, $tagmax)
{
    global $userprefix;
    $options = array('scope' => Notice::defaultScope());
    $n = rand(0, $i - 1);
    $user = User::staticGet('nickname', sprintf('%s%d', $userprefix, $n));
    $is_reply = rand(0, 1);
    $content = testNoticeContent();
    if ($is_reply == 0) {
        $stream = new InboxNoticeStream($user, $user->getProfile());
        $notices = $stream->getNotices(0, 20);
        if ($notices->N > 0) {
            $nval = rand(0, $notices->N - 1);
            $notices->fetch();
            // go to 0th
            for ($i = 0; $i < $nval; $i++) {
                $notices->fetch();
            }
            $options['reply_to'] = $notices->id;
            $dont_use_nickname = rand(0, 2);
            if ($dont_use_nickname != 0) {
                $rprofile = $notices->getProfile();
                $content = "@" . $rprofile->nickname . " " . $content;
            }
            $private_to_addressees = rand(0, 4);
            if ($private_to_addressees == 0) {
                $options['scope'] |= Notice::ADDRESSEE_SCOPE;
            }
        }
    }
    $has_hash = rand(0, 2);
    if ($has_hash == 0) {
        $hashcount = rand(0, 2);
        for ($j = 0; $j < $hashcount; $j++) {
            $h = rand(0, $tagmax);
            $content .= " #tag{$h}";
        }
    }
    $in_group = rand(0, 5);
    if ($in_group == 0) {
        $groups = $user->getGroups();
        if ($groups->N > 0) {
            $gval = rand(0, $groups->N - 1);
            $groups->fetch();
            // go to 0th
            for ($i = 0; $i < $gval; $i++) {
                $groups->fetch();
            }
            $options['groups'] = array($groups->id);
            $content = "!" . $groups->nickname . " " . $content;
            $private_to_group = rand(0, 2);
            if ($private_to_group == 0) {
                $options['scope'] |= Notice::GROUP_SCOPE;
            }
        }
    }
    $private_to_site = rand(0, 4);
    if ($private_to_site == 0) {
        $options['scope'] |= Notice::SITE_SCOPE;
    }
    $notice = Notice::saveNew($user->id, $content, 'createsim', $options);
}