Esempio n. 1
0
function savePreferencesDialog()
{
    global $dialogPreferences, $glade, $config, $radioGroup, $i18n, $gui;
    // Display preview
    $config['displayPreview'] = $dialogPreferences->get_widget('_prefDisplayPreview')->get_active();
    gtShow($glade->get_widget('_previewArea'), $config['displayPreview']);
    // Check if temporary directory is accessible
    $config['tempDirectory'] = $dialogPreferences->get_widget('_prefTempPath')->get_filenames()[0];
    if (!is_dir($config['tempDirectory'])) {
        setPreferencesNoticeBox($i18n->_('prefErrTempDir404'), $gui['CNoticeBarErrBG']);
        return false;
    }
    $accessTest = $config['tempDirectory'] . DIRECTORY_SEPARATOR . 'tmpTest';
    if (!touch($accessTest)) {
        setPreferencesNoticeBox($i18n->_('prefErrTempDirAccess', $config['tempDirectory']), $gui['CNoticeBarErrBG']);
        return false;
    }
    unlink($accessTest);
    unset($accessTest);
    $inkPath = $dialogPreferences->get_widget('_prefInkscapePath')->get_filenames();
    $config['inkscapePath'] = isset($inkPath[0]) ? $inkPath[0] : '';
    unset($inkPath);
    if (!file_exists($config['inkscapePath']) && $config['displayPreview']) {
        setPreferencesNoticeBox($i18n->_('prefErrInkscapeAccess'), $gui['CNoticeBarErrBG']);
        return false;
    }
    // Display info bar
    $config['displayInfobar'] = $dialogPreferences->get_widget('_prefDisplayInfobar')->get_active();
    gtShow($glade->get_widget('_infoBar'), $config['displayInfobar']);
    // Display navigation bar
    $config['displayNavbar'] = $dialogPreferences->get_widget('_prefDisplayNavbar')->get_active();
    gtShow($glade->get_widget('_navBar'), $config['displayNavbar']);
    // Hide upload button if upload is disabled
    $config['enableUpload'] = $dialogPreferences->get_widget('_prefUploadEnable')->get_active();
    gtShow($glade->get_widget('_btnUpload'), $config['enableUpload']);
    $i = 0;
    foreach ($radioGroup['toolbarStyle'] as $radio) {
        if ($dialogPreferences->get_widget($radio)->get_active()) {
            $config['toolbarStyle'] = $i;
            break;
        }
        $i++;
    }
    $glade->get_widget('_toolbar')->set_toolbar_style($config['toolbarStyle']);
    $i = 0;
    foreach ($radioGroup['previewArea'] as $radio) {
        if ($dialogPreferences->get_widget($radio)->get_active()) {
            $config['previewArea'] = $i;
            break;
        }
        $i++;
    }
    // Active language
    preg_match('/\\(([a-zA-Z_]*)\\)/', $dialogPreferences->get_widget('_prefLanguageSelect')->get_active_text(), $matches);
    $config['language'] = $matches[1];
    unset($matches);
    $config['uploadUsername'] = trim(gtGetText($dialogPreferences->get_widget('_prefUploadUsername')));
    $config['uploadAPIKey'] = trim(gtGetText($dialogPreferences->get_widget('_prefUploadAPIKey')));
    if ($config['enableUpload']) {
        $uploadCredWarn = '';
        if (!$config['uploadUsername']) {
            $uploadCredWarn .= '• ' . $i18n->_('prefErrNoUsername') . "\n";
        }
        if (!$config['uploadAPIKey']) {
            $uploadCredWarn .= '• ' . $i18n->_('prefErrNoAPIKey');
        } elseif (!ctype_xdigit($config['uploadAPIKey']) || strlen($config['uploadAPIKey']) !== 32) {
            $uploadCredWarn .= '• ' . $i18n->_('prefErrWrongAPIKey');
        }
        if ($uploadCredWarn) {
            $uploadCredWarn = trim($uploadCredWarn) . "\n" . $i18n->_('prefErrUploadCredentials');
            setPreferencesNoticeBox($uploadCredWarn, $gui['CNoticeBarErrBG']);
            return false;
        }
    }
    $config['NSFWTagToFlag'] = $dialogPreferences->get_widget('_prefUploadNSFW')->get_active();
    saveConfigFile();
    // @functions.php
    $dialogPreferences->get_widget('_dialogPreferences')->destroy();
}
Esempio n. 2
0
function uploadClick()
{
    global $i18n, $glade, $fileList, $appAgent, $config;
    // Check if file is loaded and proper SVG
    if (!$fileList['loadedFile']) {
        setTopBar($i18n->_('uploadNoFile'), Gtk::STOCK_DIALOG_WARNING);
        return;
    }
    if (!$fileList['properSVG']) {
        setTopBar($i18n->_('uploadWrongFile'), Gtk::STOCK_DIALOG_WARNING);
        return;
    }
    // Read and check fields
    $neededFields = [];
    $content['file'] = $fileList['currentFile'];
    $content['title'] = gtGetText('_entryTitle');
    $content['description'] = gtGetText('_entryDescription');
    $content['tags'] = gtGetText('_entryTags');
    if (trim($content['title']) === '') {
        $neededFields[] = $i18n->_('uploadFieldTitle');
    }
    if (trim($content['description']) === '') {
        $neededFields[] = $i18n->_('uploadFieldDescription');
    }
    if (trim($content['tags']) === '') {
        $neededFields[] = $i18n->_('uploadFieldTags');
    }
    if (count($neededFields) > 0) {
        setTopBar($i18n->_('uploadFillFields', implode(', ', $neededFields)), Gtk::STOCK_DIALOG_WARNING);
        return;
    }
    // everything seems to be fine - uploading
    setTopBar($i18n->_('uploadInProgress'), Gtk::STOCK_DIALOG_INFO);
    gtGTKLoop();
    // wait until top bar is set
    // If convert nsfw tag>flag is set, convert it and remove from tags
    $content['nsfw'] = '0';
    if ($config['NSFWTagToFlag']) {
        $nsfwCheck = array_map('trim', explode(',', $content['tags']));
        $nsfwFind = array_search('nsfw', $nsfwCheck);
        if ($nsfwFind !== false) {
            unset($nsfwCheck[$nsfwFind]);
            $content['tags'] = implode(', ', $nsfwCheck);
            $content['nsfw'] = '1';
            unset($nsfwCheck, $nsfwFind);
        }
    }
    // POST fields preparation
    $ch = curl_init();
    $formFields = ['user_name' => $config['uploadUsername'], 'key' => $config['uploadAPIKey'], 'title' => $content['title'], 'tags' => $content['tags'], 'description' => $content['description'], 'nsfw' => $content['nsfw'], 'svg' => new CURLFile($content['file'], mime_content_type($content['file']), 'vector.svg')];
    $chOpt = [CURLOPT_URL => 'https://openclipart.org/upload-2016.php', CURLOPT_SSL_VERIFYPEER => false, CURLOPT_HEADER => false, CURLOPT_POST => 1, CURLOPT_HTTPHEADER => ['Content-Type:multipart/form-data'], CURLOPT_POSTFIELDS => $formFields, CURLOPT_RETURNTRANSFER => true, CURLOPT_USERAGENT => $appAgent];
    curl_setopt_array($ch, $chOpt);
    $chResp = curl_exec($ch);
    $chErr = curl_error($ch);
    curl_close($ch);
    $chJson = json_decode($chResp, true);
    var_dump($chJson, $chResp);
    if (!$chErr && isset($chJson['uploaded']) && $chJson['uploaded'] == true) {
        setTopBar($i18n->_('uploadOK'), Gtk::STOCK_APPLY);
        // set the URL button
        $_btnTopURL = $glade->get_widget('_btnTopURL');
        $_btnTopURL->show();
        $_btnTopURL->set_uri($chJson['url']);
    } else {
        setTopBar($i18n->_('uploadError', $chErr), Gtk::STOCK_DIALOG_WARNING);
    }
}