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 |
|
* |