mirror of
https://github.com/Terranom674/Piwigo_Bratonien_Tools.git
synced 2026-09-19 19:54:31 +00:00
Store Bratonien base watermark separately from Piwigo native watermark
This commit is contained in:
@@ -4,36 +4,24 @@ if (!defined('PHPWG_ROOT_PATH'))
|
|||||||
die('Hacking attempt!');
|
die('Hacking attempt!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
require_once(BRATONIEN_TOOLS_PATH . 'include/watermark_base.inc.php');
|
||||||
|
|
||||||
function bratonien_tools_get_base_watermark_scale()
|
function bratonien_tools_get_base_watermark_scale()
|
||||||
{
|
{
|
||||||
if (!function_exists('conf_get_param'))
|
$config = bratonien_tools_get_base_watermark_config();
|
||||||
{
|
return max(1.0, min(1000.0, (float)$config['scale_percent']));
|
||||||
return 100.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$value = (float)conf_get_param('bratonien_watermark_base_scale_percent', 100);
|
|
||||||
return max(1.0, min(1000.0, $value > 0 ? $value : 100.0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function bratonien_tools_save_base_watermark_scale($scale_percent)
|
function bratonien_tools_save_base_watermark_scale($scale_percent)
|
||||||
{
|
{
|
||||||
if (!function_exists('conf_update_param'))
|
$config = bratonien_tools_get_base_watermark_config();
|
||||||
{
|
$config['scale_percent'] = max(1.0, min(1000.0, (float)$scale_percent));
|
||||||
throw new RuntimeException('Piwigo-Konfiguration ist nicht verfuegbar.');
|
bratonien_tools_save_base_watermark_config($config);
|
||||||
}
|
|
||||||
|
|
||||||
$scale_percent = max(1.0, min(1000.0, (float)$scale_percent));
|
|
||||||
conf_update_param('bratonien_watermark_base_scale_percent', (string)$scale_percent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function bratonien_tools_get_watermark_data()
|
function bratonien_tools_get_watermark_data()
|
||||||
{
|
{
|
||||||
if (!class_exists('ImageStdParams'))
|
$watermark = bratonien_tools_get_base_watermark_config();
|
||||||
{
|
|
||||||
require_once(PHPWG_ROOT_PATH . 'include/derivative_std_params.inc.php');
|
|
||||||
}
|
|
||||||
|
|
||||||
$watermark = ImageStdParams::get_watermark();
|
|
||||||
$files = array();
|
$files = array();
|
||||||
$watermark_dir = PHPWG_ROOT_PATH . PWG_LOCAL_DIR . 'watermarks';
|
$watermark_dir = PHPWG_ROOT_PATH . PWG_LOCAL_DIR . 'watermarks';
|
||||||
|
|
||||||
@@ -53,17 +41,17 @@ function bratonien_tools_get_watermark_data()
|
|||||||
ksort($files, SORT_NATURAL | SORT_FLAG_CASE);
|
ksort($files, SORT_NATURAL | SORT_FLAG_CASE);
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'file' => $watermark->file,
|
'file' => (string)$watermark['file'],
|
||||||
'xpos' => (int) $watermark->xpos,
|
'xpos' => (int)$watermark['xpos'],
|
||||||
'ypos' => (int) $watermark->ypos,
|
'ypos' => (int)$watermark['ypos'],
|
||||||
'xrepeat' => (int) $watermark->xrepeat,
|
'xrepeat' => (int)$watermark['xrepeat'],
|
||||||
'yrepeat' => (int) $watermark->yrepeat,
|
'yrepeat' => (int)$watermark['yrepeat'],
|
||||||
'opacity' => (int) $watermark->opacity,
|
'opacity' => (int)$watermark['opacity'],
|
||||||
'minw' => isset($watermark->min_size[0]) ? (int) $watermark->min_size[0] : 0,
|
'minw' => (int)$watermark['minw'],
|
||||||
'minh' => isset($watermark->min_size[1]) ? (int) $watermark->min_size[1] : 0,
|
'minh' => (int)$watermark['minh'],
|
||||||
'files' => $files,
|
'files' => $files,
|
||||||
'preview_url' => !empty($watermark->file) ? get_root_url() . $watermark->file : '',
|
'preview_url' => !empty($watermark['file']) ? get_root_url() . $watermark['file'] : '',
|
||||||
'scale_percent' => bratonien_tools_get_base_watermark_scale(),
|
'scale_percent' => max(1.0, min(1000.0, (float)$watermark['scale_percent'])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,12 +108,8 @@ function bratonien_tools_delete_watermark_file()
|
|||||||
throw new RuntimeException('Die Datei wird noch von folgenden Profilen verwendet: '.implode(', ', $names).'. Bitte dort zuerst eine andere Datei waehlen.');
|
throw new RuntimeException('Die Datei wird noch von folgenden Profilen verwendet: '.implode(', ', $names).'. Bitte dort zuerst eine andere Datei waehlen.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!class_exists('ImageStdParams'))
|
$current = bratonien_tools_get_base_watermark_config();
|
||||||
{
|
if (ltrim((string)$current['file'], '/') === $relative)
|
||||||
require_once(PHPWG_ROOT_PATH . 'include/derivative_std_params.inc.php');
|
|
||||||
}
|
|
||||||
$current = ImageStdParams::get_watermark();
|
|
||||||
if (ltrim((string)$current->file, '/') === $relative)
|
|
||||||
{
|
{
|
||||||
throw new RuntimeException('Die Datei ist aktuell als Basis-Wasserzeichen ausgewaehlt. Bitte zuerst eine andere Datei speichern.');
|
throw new RuntimeException('Die Datei ist aktuell als Basis-Wasserzeichen ausgewaehlt. Bitte zuerst eine andere Datei speichern.');
|
||||||
}
|
}
|
||||||
@@ -150,17 +134,8 @@ function bratonien_tools_save_watermark()
|
|||||||
throw new RuntimeException('Nur ein Piwigo-Webmaster darf das Wasserzeichen aendern.');
|
throw new RuntimeException('Nur ein Piwigo-Webmaster darf das Wasserzeichen aendern.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!class_exists('ImageStdParams'))
|
$current = bratonien_tools_get_base_watermark_config();
|
||||||
{
|
$selected_file = isset($_POST['watermark_file']) ? trim((string) $_POST['watermark_file']) : (string)$current['file'];
|
||||||
require_once(PHPWG_ROOT_PATH . 'include/derivative_std_params.inc.php');
|
|
||||||
}
|
|
||||||
if (!function_exists('clear_derivative_cache'))
|
|
||||||
{
|
|
||||||
require_once(PHPWG_ROOT_PATH . 'admin/include/functions.php');
|
|
||||||
}
|
|
||||||
|
|
||||||
$current = ImageStdParams::get_watermark();
|
|
||||||
$selected_file = isset($_POST['watermark_file']) ? trim((string) $_POST['watermark_file']) : $current->file;
|
|
||||||
|
|
||||||
if (isset($_FILES['watermark_upload']) && !empty($_FILES['watermark_upload']['tmp_name']))
|
if (isset($_FILES['watermark_upload']) && !empty($_FILES['watermark_upload']['tmp_name']))
|
||||||
{
|
{
|
||||||
@@ -219,41 +194,32 @@ function bratonien_tools_save_watermark()
|
|||||||
throw new RuntimeException('Das ausgewaehlte Wasserzeichen liegt nicht im erlaubten Wasserzeichen-Verzeichnis.');
|
throw new RuntimeException('Das ausgewaehlte Wasserzeichen liegt nicht im erlaubten Wasserzeichen-Verzeichnis.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$xpos = bratonien_tools_watermark_int('watermark_xpos', 0, 100, 90);
|
$scale_percent = isset($_POST['watermark_scale_percent']) ? (float)$_POST['watermark_scale_percent'] : (float)$current['scale_percent'];
|
||||||
$ypos = bratonien_tools_watermark_int('watermark_ypos', 0, 100, 90);
|
|
||||||
$opacity = bratonien_tools_watermark_int('watermark_opacity', 1, 100, 35);
|
|
||||||
$minw = bratonien_tools_watermark_int('watermark_minw', 0, 100000, 10);
|
|
||||||
$minh = bratonien_tools_watermark_int('watermark_minh', 0, 100000, 10);
|
|
||||||
$xrepeat = bratonien_tools_watermark_int('watermark_xrepeat', 0, 100000, 0);
|
|
||||||
$yrepeat = bratonien_tools_watermark_int('watermark_yrepeat', 0, 100000, 0);
|
|
||||||
|
|
||||||
$scale_percent = isset($_POST['watermark_scale_percent']) ? (float)$_POST['watermark_scale_percent'] : bratonien_tools_get_base_watermark_scale();
|
|
||||||
if (!is_finite($scale_percent) || $scale_percent < 1 || $scale_percent > 1000)
|
if (!is_finite($scale_percent) || $scale_percent < 1 || $scale_percent > 1000)
|
||||||
{
|
{
|
||||||
throw new RuntimeException('Die Wasserzeichengroesse muss zwischen 1 und 1000 Prozent liegen.');
|
throw new RuntimeException('Die Wasserzeichengroesse muss zwischen 1 und 1000 Prozent liegen.');
|
||||||
}
|
}
|
||||||
bratonien_tools_save_base_watermark_scale($scale_percent);
|
|
||||||
|
|
||||||
$watermark = new WatermarkParams();
|
$config = array(
|
||||||
$watermark->file = $selected_file;
|
'file' => $selected_file,
|
||||||
$watermark->xpos = $xpos;
|
'xpos' => bratonien_tools_watermark_int('watermark_xpos', 0, 100, 90),
|
||||||
$watermark->ypos = $ypos;
|
'ypos' => bratonien_tools_watermark_int('watermark_ypos', 0, 100, 90),
|
||||||
$watermark->xrepeat = $xrepeat;
|
'xrepeat' => bratonien_tools_watermark_int('watermark_xrepeat', 0, 100000, 0),
|
||||||
$watermark->yrepeat = $yrepeat;
|
'yrepeat' => bratonien_tools_watermark_int('watermark_yrepeat', 0, 100000, 0),
|
||||||
$watermark->opacity = $opacity;
|
'opacity' => bratonien_tools_watermark_int('watermark_opacity', 1, 100, 35),
|
||||||
$watermark->min_size = array($minw, $minh);
|
'minw' => bratonien_tools_watermark_int('watermark_minw', 0, 100000, 10),
|
||||||
|
'minh' => bratonien_tools_watermark_int('watermark_minh', 0, 100000, 10),
|
||||||
|
'scale_percent' => round($scale_percent, 2),
|
||||||
|
);
|
||||||
|
bratonien_tools_save_base_watermark_config($config);
|
||||||
|
|
||||||
ImageStdParams::set_watermark($watermark);
|
// If the Bratonien engine is active, native Piwigo watermarking must stay
|
||||||
|
// fully neutralized. In particular the native watermark file must remain
|
||||||
foreach (ImageStdParams::get_defined_type_map() as $type => $params)
|
// empty because Piwigo derives use_watermark from it for custom derivatives.
|
||||||
|
if (function_exists('bratonien_tools_watermark_engine_enabled') && bratonien_tools_watermark_engine_enabled())
|
||||||
{
|
{
|
||||||
ImageStdParams::apply_global($params);
|
bratonien_tools_disable_piwigo_watermarks();
|
||||||
if ($params->use_watermark)
|
|
||||||
{
|
|
||||||
$params->last_mod_time = time();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
ImageStdParams::save();
|
|
||||||
|
|
||||||
$cache_message = '';
|
$cache_message = '';
|
||||||
if (!empty($_POST['watermark_clear_cache']))
|
if (!empty($_POST['watermark_clear_cache']))
|
||||||
@@ -269,7 +235,7 @@ function bratonien_tools_save_watermark()
|
|||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'message' => 'Wasserzeichen gespeichert.' . $cache_message,
|
'message' => 'Basis-Wasserzeichen gespeichert.' . $cache_message,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user