Пример #1
0
function resetFields($field_names, $new_value = '', $type = 'text', $date_format = 'm/d/Y')
{
    global $form;
    if (is_array($field_names)) {
        //field_names is already an array
        foreach ($field_names as $name) {
            resetFields($name, $new_value, $type, $date_format);
        }
    } elseif (strpos($field_names, ',') !== false) {
        //field_names is comma-delimited
        $field_names = explode(',', $field_names);
        foreach ($field_names as $name) {
            resetFields(trim($name), $new_value, $type, $date_format);
        }
    } elseif ($field_names != '') {
        //assume field_names is one field
        switch ($type) {
            case 'array':
                if (is_array($new_value)) {
                    $form[$field_names] = $new_value;
                } elseif ($new_value != '') {
                    $form[$field_names] = array($new_value);
                } else {
                    $form[$field_names] = array();
                }
                array_walk($form[$field_names], 'arrayMod', array('action' => 'trim'));
                break;
            case 'int':
                $form[$field_names] = intval($new_value);
                break;
            case 'posint':
                $form[$field_names] = intval($new_value);
                if ($form[$field_names] < 1) {
                    $form[$field_names] = NULL;
                }
                break;
            case 'float':
                $form[$field_names] = floatval($new_value);
                break;
            case 'float2':
                $form[$field_names] = number_format(floatval($new_value), 2);
                break;
            case 'date':
                $form[$field_names] = $new_value != '' ? date($date_format, safeStrToTime($new_value)) : '';
                break;
            case 'year':
                $form[$field_names] = intval($new_value > 0) ? intval($new_value) : '';
                break;
            default:
                $form[$field_names] = trim($new_value);
        }
    }
}
Пример #2
0
function readSVG($file)
{
    global $fields, $config, $timerSpin, $_navName, $_navIndex, $_btnNav, $fileList, $_btnNavRefresh, $i18n;
    if (is_dir($file)) {
        setTopBar($i18n->_('loadProblemsDir', basename($file)), Gtk::STOCK_DIALOG_WARNING);
        return;
    }
    if (!file_exists($file)) {
        setTopBar($i18n->_('loadProblems', basename($file)), Gtk::STOCK_DIALOG_WARNING);
        return;
    }
    resetFields();
    $_btnNavRefresh->set_sensitive(true);
    // Enable refresh button with first (and every other) reading file
    // Set navigation bar - it's done everytime file is loading to refresh directory, which could change meanwhile
    $fileList['directory'] = dirname($file);
    $fileList['currentFile'] = $file;
    $fileList['globFix'] = strtr($fileList['directory'], ['[' => '[[]', ']' => '[]]']);
    $fileList['list'] = glob($fileList['globFix'] . DIRECTORY_SEPARATOR . "*.[Ss][Vv][Gg]");
    $fileList['total'] = count($fileList['list']);
    $fileList['current'] = intval(array_search($file, $fileList['list'])) + 1;
    $fileList['isLast'] = $fileList['current'] === $fileList['total'];
    $fileList['isFirst'] = $fileList['current'] === 1;
    // As index is set during loading, the destination files for nav buttons are set same time, to avoid weird behavior on directory change
    if (!$fileList['isFirst']) {
        $fileList['nav'][-2] = $fileList['list'][0];
        $fileList['nav'][-1] = $fileList['list'][$fileList['current'] - 2];
    }
    if (!$fileList['isLast']) {
        $fileList['nav'][1] = $fileList['list'][$fileList['current']];
        $fileList['nav'][2] = $fileList['list'][$fileList['total'] - 1];
    }
    // For now navigation buttons don't loop, so turn off unusable and on usable
    $_btnNav[-2]->set_sensitive(!$fileList['isFirst']);
    $_btnNav[-1]->set_sensitive(!$fileList['isFirst']);
    $_btnNav[1]->set_sensitive(!$fileList['isLast']);
    $_btnNav[2]->set_sensitive(!$fileList['isLast']);
    gtSetText($_navName, basename($file));
    gtSetText($_navIndex, $fileList['current'] . '/' . $fileList['total']);
    // That's to be changed, as SVG with embedded raster files aren't recognized as image/svg+xml
    if (mime_content_type($file) === 'image/svg+xml') {
        $fileList['properSVG'] = true;
        if ($config['displayPreview']) {
            // display preview only when it's visible, so people without Inkscape won't get errors
            // Generate preview
            $outputFile = $config['tempDirectory'] . DIRECTORY_SEPARATOR . uniqid('preview', true) . '.png';
            $previewArea = ['page', 'drawing'];
            $cmdPreview = '--export-area-' . $previewArea[$config['previewArea']];
            if (!empty($timerSpin)) {
                Gtk::timeout_remove($timerSpin);
            }
            // needed for navigating to other file before preview is done
            $timerSpin = Gtk::timeout_add(250, 'timerSpin', $outputFile);
            // checking for Inkscape preview to be done
            spinnerToggle(true);
            // This command runs asynchronously two synchronous commands, so _after_ Inkscape is done it
            // creates an empty file, so app would know when file is ready.
            $asynchFix = detectOS(HK_OS_WINDOWS) ? "& type nul >>\"{$outputFile}.nul\"" : "&& touch \"{$outputFile}.nul\"";
            execQuiet("\"{$config['inkscapePath']}\" --file=\"{$file}\" -w=200 {$cmdPreview} --export-png=\"{$outputFile}\" {$asynchFix}", true);
        }
        // Get SVG metadata
        $meta = getSVGMetadata($file);
        if (!$meta) {
            // Parsing metadata error
            setTopBar(sprintf(_('%s metadata not found'), basename($file)), Gtk::STOCK_CAPS_LOCK_WARNING);
            return;
        }
        // Parsing metadata ok
        foreach ($fields as $id) {
            gtSetText("_entry{$id}", $meta[$id]);
        }
        setTopBar(sprintf(_('%s parsed'), basename($file)), Gtk::STOCK_APPLY);
    } else {
        // Not SVG file
        $fileList['properSVG'] = false;
        setTopBar($i18n->_('loadIncorrectSVG', basename($file)), Gtk::STOCK_DIALOG_WARNING);
    }
    $fileList['loadedFile'] = true;
}