Esempio n. 1
0
function fileupload_process($file)
{
    $attachment = handle_file($file);
    if (is_array($attachment)) {
        $html = getHTML($attachment);
        $response = array('success' => true, 'html' => $html, 'attach' => $attachment['id']);
        echo json_encode($response);
        exit;
    }
    $response = array('success' => false);
    echo json_encode($response);
    exit;
}
Esempio n. 2
0
function mod_8_flags($b)
{
    global $config, $mod, $board;
    require_once 'inc/image.php';
    if (!hasPermission($config['mod']['edit_flags'], $b)) {
        error($config['error']['noaccess']);
    }
    if (!openBoard($b)) {
        error("Could not open board!");
    }
    if (file_exists("{$b}/flags.ser")) {
        $config['user_flags'] = unserialize(file_get_contents("{$b}/flags.ser"));
    }
    $dir = 'static/custom-flags/' . $b;
    if (!is_dir($dir)) {
        mkdir($dir, 0777, true);
    }
    function handle_file($id = false, $description, $b, $dir)
    {
        global $config;
        if (!isset($description) and $description) {
            error(_('You must enter a flag description!'));
        }
        if (strlen($description) > 255) {
            error(_('Flag description too long!'));
        }
        if ($id) {
            $f = 'flag-' . $id;
        } else {
            $f = 'file';
            $id = time() . substr(microtime(), 2, 3);
        }
        $upload = $_FILES[$f]['tmp_name'];
        $banners = array_diff(scandir($dir), array('..', '.'));
        if (!is_readable($upload)) {
            error($config['error']['nomove']);
        }
        $extension = strtolower(mb_substr($_FILES[$f]['name'], mb_strrpos($_FILES[$f]['name'], '.') + 1));
        if ($extension != 'png') {
            error(_('Flags must be in PNG format.'));
        }
        if (filesize($upload) > 48000) {
            error(_('File too large!'));
        }
        if (!($size = @getimagesize($upload))) {
            error($config['error']['invalidimg']);
        }
        if ($size[0] > 20 or $size[0] < 11 or $size[1] > 16 or $size[1] < 11) {
            error(_('Image wrong size!'));
        }
        if (sizeof($banners) > 256) {
            error(_('Too many flags.'));
        }
        copy($upload, "{$dir}/{$id}.{$extension}");
        purge("{$dir}/{$id}.{$extension}", true);
        $config['user_flags'][$id] = utf8tohtml($description);
        file_write($b . '/flags.ser', serialize($config['user_flags']));
    }
    // Handle a new flag, if any.
    if (isset($_FILES['file'])) {
        handle_file(false, $_POST['description'], $b, $dir);
    }
    // Handle edits to existing flags.
    foreach ($_FILES as $k => $a) {
        if (empty($_FILES[$k]['tmp_name'])) {
            continue;
        }
        if (preg_match('/^flag-(\\d+)$/', $k, $matches)) {
            $id = (int) $matches[1];
            if (!isset($_POST['description-' . $id])) {
                continue;
            }
            if (isset($config['user_flags'][$id])) {
                handle_file($id, $_POST['description-' . $id], $b, $dir);
            }
        }
    }
    // Description just changed, flag not edited.
    foreach ($_POST as $k => $v) {
        if (!preg_match('/^description-(\\d+)$/', $k, $matches)) {
            continue;
        }
        $id = (int) $matches[1];
        if (!isset($_POST['description-' . $id])) {
            continue;
        }
        $description = $_POST['description-' . $id];
        if (strlen($description) > 255) {
            error(_('Flag description too long!'));
        }
        $config['user_flags'][$id] = utf8tohtml($description);
        file_write($b . '/flags.ser', serialize($config['user_flags']));
    }
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
        $flags = <<<FLAGS
<?php
\$config['country_flags'] = false;
\$config['country_flags_condensed'] = false;
\$config['user_flag'] = true;
\$config['uri_flags'] = '/static/custom-flags/{$b}/%s.png';
\$config['flag_style'] = '';
\$config['user_flags'] = unserialize(file_get_contents('{$b}/flags.ser'));
FLAGS;
        if ($config['cache']['enabled']) {
            cache::delete('config_' . $b);
            cache::delete('events_' . $b);
        }
        file_write($b . '/flags.php', $flags);
    }
    if (isset($_POST['delete'])) {
        foreach ($_POST['delete'] as $i => $d) {
            if (!preg_match('/[0-9+]/', $d)) {
                error('Nice try.');
            }
            unlink("{$dir}/{$d}.png");
            $id = explode('.', $d)[0];
            unset($config['user_flags'][$id]);
            file_write($b . '/flags.ser', serialize($config['user_flags']));
        }
    }
    if (isset($_POST['alphabetize'])) {
        asort($config['user_flags'], SORT_NATURAL | SORT_FLAG_CASE);
        file_write($b . '/flags.ser', serialize($config['user_flags']));
    }
    $banners = array_diff(scandir($dir), array('..', '.'));
    mod_page(_('Edit flags'), 'mod/flags.html', array('board' => $board, 'banners' => $banners, 'token' => make_secure_link_token('banners/' . $board['uri'])));
}