コード例 #1
0
ファイル: subs.php プロジェクト: GallardoAlba/Meneame
function print_tabs($option)
{
    global $current_user;
    if (SitesMgr::my_id() == 1 && SitesMgr::can_edit(0)) {
        $can_edit = true;
    } else {
        $can_edit = false;
    }
    $items = array();
    if ($current_user->user_id) {
        $items[] = array('id' => 0, 'url' => 'subs', 'title' => _('suscripciones'));
    }
    $items[] = array('id' => 1, 'url' => 'subs?active', 'title' => _('más activos'));
    $items[] = array('id' => 2, 'url' => 'subs?all', 'title' => _('todos'));
    if ($can_edit) {
        $items[] = array('id' => 3, 'url' => 'subedit', 'title' => _('crear sub'));
    }
    $vars = compact('items', 'option');
    return Haanga::Load('print_tabs.html', $vars);
}
コード例 #2
0
ファイル: user.php プロジェクト: GallardoAlba/Meneame
function do_subs()
{
    global $db, $user, $current_user;
    $sql = "select subs.* from subs, prefs where pref_user_id = {$user->id} and pref_key = 'sub_follow' and subs.id = pref_value order by name asc";
    $subs = $db->get_results($sql);
    if ($subs) {
        $title = _('suscripciones');
        Haanga::Load('subs_simple.html', compact('title', 'subs'));
    }
    if ($current_user->admin && $user->id == $current_user->user_id) {
        $sql = "select subs.* from subs where subs.sub = 1 and (subs.owner = {$user->id} or subs.owner = 0)";
    } else {
        $sql = "select subs.* from subs where subs.sub = 1 and subs.owner = {$user->id}";
    }
    $subs = $db->get_results($sql);
    if ($subs) {
        $title = _('subs de') . " {$user->username}";
        if ($current_user->user_id > 0 && $user->id == $current_user->user_id && SitesMgr::can_edit(0)) {
            $can_edit = true;
        } else {
            $can_edit = false;
        }
        Haanga::Load('subs.html', compact('title', 'subs', 'can_edit'));
    }
}
コード例 #3
0
ファイル: subedit.php プロジェクト: GallardoAlba/Meneame
function save_sub($id, &$errors)
{
    global $current_user, $db;
    // Double check
    $owner = intval($_POST['owner']);
    if (!SitesMgr::can_edit($id)) {
        array_push($errors, _('usuario no autorizado a editar'));
        return false;
    }
    $site = SitesMgr::get_info();
    $extended = SitesMgr::get_extended_properties($id);
    if ($_POST['created_from'] != $site->id) {
        array_push($errors, _('sitio erróneo'));
    }
    if ($owner != $current_user->user_id && !$current_user->admin) {
        array_push($errors, _('propietario erróneo'));
    }
    $name = mb_substr(clean_input_string($_POST['name']), 0, 12);
    if (mb_strlen($name) < 3 || !preg_match('/^\\p{L}[\\p{L}\\d_]+$/u', $name)) {
        array_push($errors, _('nombre erróneo') . ' ' . $_POST['name']);
    }
    $name_long = mb_substr(clean_text($_POST['name_long']), 0, 40);
    if (mb_strlen($name_long) < 6) {
        array_push($errors, _('título erróneo'));
    }
    $name = $db->escape($name);
    $name_long = $db->escape($name_long);
    if ($db->get_var("select count(*) from subs where name = '{$name}' and id != {$id}") > 0) {
        array_push($errors, _('nombre duplicado'));
    }
    $page_mode = $db->escape($_POST['page_mode']);
    if ($current_user->admin) {
        $enabled = intval($_POST['enabled']);
        $allow_main_link = intval($_POST['allow_main_link']);
    } else {
        // Keep the values
        $enabled = $site->enabled;
        $allow_main_link = $site->allow_main_link;
        $_POST['post_html'] = $extended['post_html'];
    }
    $nsfw = intval($_POST['nsfw']);
    $private = intval($_POST['private']);
    // Check the extended info
    foreach (array('no_link', 'no_anti_spam', 'allow_local_links', 'intro_max_len', 'intro_min_len') as $k) {
        if (isset($_POST[$k]) && $_POST[$k] !== '') {
            $_POST[$k] = intval($_POST[$k]);
        }
    }
    if ($_POST['intro_max_len'] > 5000) {
        $_POST['intro_max_len'] = 5000;
    }
    if (empty($errors)) {
        $db->transaction();
        if ($id > 0) {
            $r = $db->query("update subs set owner = {$owner}, enabled = {$enabled}, allow_main_link = {$allow_main_link}, nsfw = {$nsfw}, name = '{$name}', name_long = '{$name_long}', private = {$private}, page_mode = '{$page_mode}' where id = {$id}");
        } else {
            $r = $db->query("insert into subs (created_from, owner, nsfw, name, name_long, sub, private) values ({$site->id}, {$owner}, {$nsfw}, '{$name}', '{$name_long}', 1, {$private})");
            $id = $db->insert_id;
        }
        if ($r && $id > 0) {
            // Copy values from first site
            $r = $db->query("update subs as a join subs as b on a.id = {$id} and b.id={$site->id} set a.server_name = b.server_name, a.base_url = b.base_url");
            // Update copy_from
            if ($current_user->admin) {
                sub_copy_from($id, $_POST['copy_from']);
            }
            // Update colors
            $color_regex = '/^#[a-f0-9]{6}/i';
            if (preg_match($color_regex, $_POST['color1'])) {
                $color1 = $db->escape($_POST['color1']);
            } else {
                $color1 = '';
            }
            if (preg_match($color_regex, $_POST['color2'])) {
                $color2 = $db->escape($_POST['color2']);
            } else {
                $color2 = '';
            }
            $db->query("update subs set color1 = '{$color1}', color2 = '{$color2}' where id = {$id}");
        }
        if ($r && $id > 0) {
            SitesMgr::store_extended_properties($id, $_POST);
            $db->commit();
            store_image($id);
            return $id;
        } else {
            array_push($errors, _('error actualizando la base de datos'));
            $db->rollback();
        }
    }
    return false;
}