Пример #1
0
function link_edit_errors($link)
{
    global $current_user, $globals;
    $errors = array();
    if ($link->sub_id > 0 && !SitesMgr::is_owner() && !SitesMgr::can_send($link->sub_id)) {
        $errors[] = _('no se puede enviar a ese sub');
        $error = true;
    }
    // only checks if the user is not special or god
    if (!empty($link->url) && !$link->check_url($link->url, false) && !$current_user->admin) {
        $errors[] = _('url incorrecto');
    }
    if ($_POST['key'] !== md5($_POST['timestamp'] . $link->randkey)) {
        $errors[] = _('clave incorrecta');
        $error = true;
    }
    if (time() - $_POST['timestamp'] > 900) {
        $errors[] = _('tiempo excedido');
    }
    $errors = array_merge($errors, $link->check_field_errors());
    return $errors;
}
Пример #2
0
function print_subs_form($selected = false)
{
    global $db, $globals, $current_user;
    function id($s)
    {
        return $s->id;
    }
    if (!empty($globals['submnm'])) {
        $subs = false;
    } else {
        $subs = SitesMgr::get_sub_subs();
        $ids = array_map('id', $subs);
        // A link in a sub is edited from another sub, or from the main site
        // Add its selected sub.
        if ($selected != false && !in_array($selected, $ids) && SitesMgr::can_send($selected)) {
            $e = SitesMgr::get_info($selected);
            if ($e) {
                array_unshift($subs, $e);
                // Add to the form
                array_unshift($ids, $selected);
                // Avoid to show it again if subscribed to
            }
        }
        $extras = SitesMgr::get_subscriptions($current_user->user_id);
        // Don't repeat the same subs
        $subscriptions = array();
        foreach ($extras as $s) {
            if (!in_array($s->id, $ids) && SitesMgr::can_send($s->id)) {
                $subscriptions[] = $s;
            }
        }
    }
    if ($selected == false) {
        $selected = SitesMgr::my_id();
    }
    $vars = compact('selected', 'subs', 'subscriptions');
    return Haanga::Load('form_subs.html', $vars);
}
Пример #3
0
function link_errors($link)
{
    global $globals, $current_user, $site_key;
    $error = false;
    // Errors
    if (!check_link_key() || intval($_POST['randkey']) != $link->randkey) {
        add_submit_error(_("clave incorrecta"));
        $error = true;
    }
    if ($link->sub_id > 0 && !SitesMgr::can_send($link->sub_id)) {
        add_submit_error(_("envío deshabilitados en") . " {$link->sub_name}");
        $error = true;
    }
    if ($link->status != 'discard') {
        add_submit_error(_("la historia ya está en cola") . ": {$link->status}");
        $error = true;
    }
    // TODO: simplify this, return just $errors as array()
    // as in editlink
    $res = $link->check_field_errors();
    if (!empty($res)) {
        $error = true;
        foreach ($res as $e) {
            add_submit_error($e);
        }
    }
    return $error;
}