mirror of
https://github.com/Terranom674/Piwigo_Bratonien_Tools.git
synced 2026-09-19 12:54:31 +00:00
Add watermark engine activation and Piwigo backup restore
This commit is contained in:
@@ -15,6 +15,7 @@ function bratonien_tools_get_watermark_engine_config()
|
|||||||
$default = array(
|
$default = array(
|
||||||
'enabled' => false,
|
'enabled' => false,
|
||||||
'restore_piwigo' => true,
|
'restore_piwigo' => true,
|
||||||
|
'piwigo_backup' => null,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!function_exists('conf_get_param'))
|
if (!function_exists('conf_get_param'))
|
||||||
@@ -32,6 +33,11 @@ function bratonien_tools_get_watermark_engine_config()
|
|||||||
return is_array($decoded) ? array_merge($default, $decoded) : $default;
|
return is_array($decoded) ? array_merge($default, $decoded) : $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function bratonien_tools_save_watermark_engine_config($config)
|
||||||
|
{
|
||||||
|
conf_update_param('bratonien_watermark_engine', json_encode($config));
|
||||||
|
}
|
||||||
|
|
||||||
function bratonien_tools_set_watermark_engine($enabled)
|
function bratonien_tools_set_watermark_engine($enabled)
|
||||||
{
|
{
|
||||||
if (!function_exists('conf_update_param'))
|
if (!function_exists('conf_update_param'))
|
||||||
@@ -40,9 +46,62 @@ function bratonien_tools_set_watermark_engine($enabled)
|
|||||||
}
|
}
|
||||||
|
|
||||||
$config = bratonien_tools_get_watermark_engine_config();
|
$config = bratonien_tools_get_watermark_engine_config();
|
||||||
$config['enabled'] = (bool) $enabled;
|
|
||||||
|
|
||||||
conf_update_param('bratonien_watermark_engine', json_encode($config));
|
if ($enabled && empty($config['enabled']))
|
||||||
|
{
|
||||||
|
$config['piwigo_backup'] = bratonien_tools_backup_piwigo_watermark_settings();
|
||||||
|
bratonien_tools_disable_piwigo_watermarks();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$enabled && !empty($config['enabled']) && !empty($config['restore_piwigo']))
|
||||||
|
{
|
||||||
|
bratonien_tools_restore_piwigo_watermark_settings($config['piwigo_backup']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$config['enabled'] = (bool) $enabled;
|
||||||
|
bratonien_tools_save_watermark_engine_config($config);
|
||||||
|
}
|
||||||
|
|
||||||
|
function bratonien_tools_backup_piwigo_watermark_settings()
|
||||||
|
{
|
||||||
|
if (!class_exists('ImageStdParams'))
|
||||||
|
{
|
||||||
|
require_once(PHPWG_ROOT_PATH . 'include/derivative_std_params.inc.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
$backup = array();
|
||||||
|
|
||||||
|
foreach (ImageStdParams::get_defined_type_map() as $type => $params)
|
||||||
|
{
|
||||||
|
$backup[$type] = array(
|
||||||
|
'use_watermark' => (bool) $params->use_watermark,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $backup;
|
||||||
|
}
|
||||||
|
|
||||||
|
function bratonien_tools_restore_piwigo_watermark_settings($backup)
|
||||||
|
{
|
||||||
|
if (!is_array($backup))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!class_exists('ImageStdParams'))
|
||||||
|
{
|
||||||
|
require_once(PHPWG_ROOT_PATH . 'include/derivative_std_params.inc.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (ImageStdParams::get_defined_type_map() as $type => $params)
|
||||||
|
{
|
||||||
|
if (isset($backup[$type]['use_watermark']))
|
||||||
|
{
|
||||||
|
$params->use_watermark = (bool) $backup[$type]['use_watermark'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageStdParams::save();
|
||||||
}
|
}
|
||||||
|
|
||||||
function bratonien_tools_disable_piwigo_watermarks()
|
function bratonien_tools_disable_piwigo_watermarks()
|
||||||
|
|||||||
Reference in New Issue
Block a user