From 63aa9e9708967155121b50097e9e0faae6425ef0 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Tue, 26 Jun 2012 12:00:03 +0200 Subject: [PATCH 1/3] Fix #760 watermark issue --- lib/Alchemy/Phrasea/Application/Overview.php | 2 +- lib/Alchemy/Phrasea/Out/Module/PDF.php | 4 +- lib/classes/recordutils/image.class.php | 49 +++++++------------- lib/classes/set/export.class.php | 5 +- 4 files changed, 20 insertions(+), 40 deletions(-) diff --git a/lib/Alchemy/Phrasea/Application/Overview.php b/lib/Alchemy/Phrasea/Application/Overview.php index ba6d6eccfb..0e334d09d1 100644 --- a/lib/Alchemy/Phrasea/Application/Overview.php +++ b/lib/Alchemy/Phrasea/Application/Overview.php @@ -36,7 +36,7 @@ return call_user_func( $pathIn = $pathOut = $file->get_pathfile(); if ($watermark === true && $file->get_type() === \media_subdef::TYPE_IMAGE) { - $pathOut = \recordutils_image::watermark($record->get_base_id(), $record->get_record_id()); + $pathOut = \recordutils_image::watermark($file); } elseif ($stamp === true && $file->get_type() === \media_subdef::TYPE_IMAGE) { $pathOut = \recordutils_image::stamp($record->get_base_id(), $record->get_record_id()); } diff --git a/lib/Alchemy/Phrasea/Out/Module/PDF.php b/lib/Alchemy/Phrasea/Out/Module/PDF.php index 6ea1c936ff..e41d587738 100644 --- a/lib/Alchemy/Phrasea/Out/Module/PDF.php +++ b/lib/Alchemy/Phrasea/Out/Module/PDF.php @@ -168,7 +168,7 @@ class PDF if ( ! $user->ACL()->has_right_on_base($rec->get_base_id(), "nowatermark") && $subdef->get_type() == \media_subdef::TYPE_IMAGE) { - $fimg = \recordutils_image::watermark($rec->get_base_id(), $rec->get_record_id()); + $fimg = \recordutils_image::watermark($subdef); } $wimg = $himg = $ImgSize; @@ -436,7 +436,7 @@ class PDF if ( ! $user->ACL()->has_right_on_base($rec->get_base_id(), "nowatermark") && $subdef->get_type() == \media_subdef::TYPE_IMAGE) - $f = \recordutils_image::watermark($rec->get_base_id(), $rec->get_record_id()); + $f = \recordutils_image::watermark($subdef); $wimg = $himg = 150; // preview dans un carre de 150 mm if ($subdef->get_width() > 0 && $subdef->get_height() > 0) { diff --git a/lib/classes/recordutils/image.class.php b/lib/classes/recordutils/image.class.php index 19e76564f6..34bc46c5f5 100644 --- a/lib/classes/recordutils/image.class.php +++ b/lib/classes/recordutils/image.class.php @@ -339,47 +339,30 @@ class recordutils_image extends recordutils /** * - * @param int $bas - * @param int $rec - * @param boolean $hd - * @return string + * @param \media_subdef $subdef + * @return boolean|string */ - public static function watermark($bas, $rec, $hd = false) + public static function watermark(\media_subdef $subdef) { $appbox = appbox::get_instance(\bootstrap::getCore()); $registry = $appbox->get_registry(); + $base_id = $subdef->get_record()->get_base_id(); - $sbas_id = phrasea::sbasFromBas($bas); - - if ( ! isset($sbas_id)) { - return false; + if ($subdef->get_name() !== 'preview') { + return $subdef->get_pathfile(); } - $connSbas = connection::getPDOConnection($sbas_id); - - $sql = "SELECT s.path, s.file, s.mime, r.type, r.xml - FROM subdef s, record r - WHERE r.record_id = :record_id AND r.record_id = s.record_id AND name='preview'"; - - $stmt = $connSbas->prepare($sql); - $stmt->execute(array(':record_id' => $rec)); - $row = $stmt->fetch(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - if ( ! $row) { - return false; + if ($subdef->get_type() !== \media_subdef::TYPE_IMAGE) { + return $subdef->get_pathfile(); } - $file = array( - 'type' => $row['type'] - , 'path' => p4string::addEndSlash($row['path']) - , 'file' => $row['file'] - , 'mime' => $row['mime'] - ); + if ( ! $subdef->is_physically_present()) { + return $subdef->get_pathfile(); + } - $pathIn = $file['path'] . $file['file']; + $pathIn = $subdef->get_path() . $subdef->get_file(); - $pathOut = $file['path'] . 'watermark_' . $file['file']; + $pathOut = $subdef->get_path() . 'watermark_' . $subdef->get_file(); if ( ! is_file($pathIn)) { return false; @@ -390,9 +373,9 @@ class recordutils_image extends recordutils } if ($registry->get('GV_pathcomposite') && - file_exists($registry->get('GV_RootPath') . 'config/wm/' . $bas)) { // si il y a un WM + file_exists($registry->get('GV_RootPath') . 'config/wm/' . $base_id)) { // si il y a un WM $cmd = $registry->get('GV_pathcomposite') . " "; - $cmd .= $registry->get('GV_RootPath') . 'config/wm/' . $bas . " "; + $cmd .= $registry->get('GV_RootPath') . 'config/wm/' . $base_id . " "; $cmd .= " \"" . $pathIn . "\" "; # <<-- la preview original $cmd .= " -strip -watermark 90% -gravity center "; $cmd .= " \"" . $pathOut . "\""; # <-- la preview temporaire @@ -414,7 +397,7 @@ class recordutils_image extends recordutils $return_value = proc_close($process); } } elseif ($registry->get('GV_imagick')) { - $collname = phrasea::bas_names($bas); + $collname = phrasea::bas_names($base_id); $cmd = $registry->get('GV_imagick'); $tailleimg = @getimagesize($pathIn); $max = ($tailleimg[0] > $tailleimg[1] ? $tailleimg[0] : $tailleimg[1]); diff --git a/lib/classes/set/export.class.php b/lib/classes/set/export.class.php index 0a8b606b90..da3aab94b5 100644 --- a/lib/classes/set/export.class.php +++ b/lib/classes/set/export.class.php @@ -516,10 +516,7 @@ class set_export extends set_abstract if ( ! $user->ACL()->has_right_on_base($download_element->get_base_id(), "nowatermark") && ! $user->ACL()->has_preview_grant($download_element) && $sd[$name]->get_type() == media_subdef::TYPE_IMAGE) { - $path = recordutils_image::watermark( - $download_element->get_base_id() - , $download_element->get_record_id() - ); + $path = recordutils_image::watermark($sd[$name]); if (file_exists($path)) { $tmp_pathfile = array( 'path' => dirname($path) From 1aaeec8eb5e7980f31074fa3236838e5c34504e1 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Tue, 26 Jun 2012 12:05:25 +0200 Subject: [PATCH 2/3] Fix #758 Disable thesaurus Pane for user who do not have access to it --- templates/web/prod/index.html.twig | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/templates/web/prod/index.html.twig b/templates/web/prod/index.html.twig index 1e3107b2a4..a56f0d1093 100644 --- a/templates/web/prod/index.html.twig +++ b/templates/web/prod/index.html.twig @@ -178,8 +178,18 @@
+ {% if user.ACL().has_access_to_module('thesaurus') %}
@@ -232,6 +243,7 @@
+ {% endif %}