@@ -184,6 +184,12 @@
Loading
184 184
                session_start();
185 185
            }
186 186
        }
187 +
188 +
        // Flash message, use it when redirecting page.
189 +
        if (! empty($_SESSION['flash_messages'])) {
190 +
            $this->messages = $_SESSION['flash_messages'];
191 +
            unset($_SESSION['flash_messages']);
192 +
        }
187 193
    }
188 194
189 195
     // @codeCoverageIgnoreStart
@@ -303,6 +309,14 @@
Loading
303 309
                $this->login();
304 310
                break;
305 311
312 +
            case 'export_settings':
313 +
                $this->exportSettings();
314 +
                break;
315 +
316 +
            case 'import_settings':
317 +
                $this->importSettings();
318 +
                break;
319 +
306 320
            default:
307 321
                header('Location: ' . $this->url('login'));
308 322
                break;
@@ -1773,6 +1787,97 @@
Loading
1773 1787
        }
1774 1788
    }
1775 1789
1790 +
    /**
1791 +
     * Export settings.
1792 +
     *
1793 +
     * @return void
1794 +
     */
1795 +
    protected function exportSettings()
1796 +
    {
1797 +
        header('Content-type: text/plain');
1798 +
        header('Content-Disposition: attachment; filename=shieldon-' . date('YmdHis') . '.json');
1799 +
        header('Expires: 0');
1800 +
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
1801 +
        header('Pragma: public');
1802 +
        echo json_encode($this->configuration);
1803 +
    }
1804 +
1805 +
    /**
1806 +
     * Import settings.
1807 +
     *
1808 +
     * @return void
1809 +
     */
1810 +
    protected function importSettings()
1811 +
    {
1812 +
        if (! empty($_FILES['json_file']['tmp_name'])) {
1813 +
            $importedFileContent = file_get_contents($_FILES['json_file']['tmp_name']);
1814 +
        }
1815 +
1816 +
        if (! empty($importedFileContent)) {
1817 +
            $jsonData = json_decode($importedFileContent, true);
1818 +
1819 +
            if (json_last_error() !== JSON_ERROR_NONE) {
1820 +
                $this->responseMessage('error',
1821 +
                    __(
1822 +
                        'panel',
1823 +
                        'error_invalid_json_file',
1824 +
                        'Invalid JSON file.'
1825 +
                    )
1826 +
                );
1827 +
1828 +
                $_SESSION['flash_messages'] = $this->messages;
1829 +
                header('Location: ' . $this->url('settings'));
1830 +
                exit;
1831 +
            }
1832 +
1833 +
            $checkFileVaild = true;
1834 +
1835 +
            foreach (array_keys($this->configuration) as $key) {
1836 +
                if (! isset($jsonData[$key])) {
1837 +
                    $checkFileVaild = false;
1838 +
                }
1839 +
            }
1840 +
1841 +
            if ($checkFileVaild) {
1842 +
                foreach (array_keys($jsonData) as $key) {
1843 +
                    if (isset($this->configuration[$key])) {
1844 +
                        unset($this->configuration[$key]);
1845 +
                    }
1846 +
                }
1847 +
1848 +
                $this->configuration = $this->configuration + $jsonData;
1849 +
1850 +
                // Save settings into a configuration file.
1851 +
                $configFilePath = $this->directory . '/' . $this->filename;
1852 +
                file_put_contents($configFilePath, json_encode($this->configuration));
1853 +
1854 +
                $this->responseMessage('success',
1855 +
                    __(
1856 +
                        'panel',
1857 +
                        'success_json_imported',
1858 +
                        'JSON file imported successfully.'
1859 +
                    )
1860 +
                );
1861 +
1862 +
                $_SESSION['flash_messages'] = $this->messages;
1863 +
                header('Location: ' . $this->url('settings'));
1864 +
                exit;
1865 +
            }
1866 +
        }
1867 +
1868 +
        $this->responseMessage('error',
1869 +
            __(
1870 +
                'panel',
1871 +
                'error_invalid_config_file',
1872 +
                'Invalid Shieldon configuration file.'
1873 +
            )
1874 +
        );
1875 +
1876 +
        $_SESSION['flash_messages'] = $this->messages;
1877 +
        header('Location: ' . $this->url('settings'));
1878 +
        exit;
1879 +
    }
1880 +
1776 1881
    /**
1777 1882
     * Echo the setting string to the template.
1778 1883
     *
Files Complexity Coverage
src/Shieldon 850 99.75%
Project Totals (30 files) 850 99.75%
167.2
10.0=0.0
TRAVIS_OS_NAME=linux
167.1
10.0=0.0
TRAVIS_OS_NAME=linux

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading