From c13a83c41727d9400a78dbee99c105255c669079 Mon Sep 17 00:00:00 2001 From: Randy Viosca Date: Fri, 20 Oct 2023 17:58:26 -0500 Subject: [PATCH] Fix Issue #2 Fixed: PHP Warnings due to initialized template variable. Cleaned up english lang translations. Modified Maintenance mode to put checks before actions. Some logic in had to be modified to prevent empty/corrupt fields, etc. --- include/Back2Front.php | 54 ++++++++++++++++++++++------------ language/en_UK/plugin.lang.php | 22 +++++++------- pem_metadata.txt | 4 +++ template/picture_modify.tpl | 8 ++--- 4 files changed, 55 insertions(+), 33 deletions(-) create mode 100644 pem_metadata.txt diff --git a/include/Back2Front.php b/include/Back2Front.php index 0533973..43bda81 100644 --- a/include/Back2Front.php +++ b/include/Back2Front.php @@ -4,7 +4,11 @@ include_once(B2F_PATH.'include/functions.inc.php'); /* - * Add verso link on picture page + * Add the back (verso) link on image page. + * Terminology note: + * Recto: means the front of something, like the right page in a book, think recto, right side. + * Verso: means the back of something, like a coin, or the left page in a book. think reVERSO, or vice versa. + * It is a little counter-intuitive. In english, it's easy to think of the backside one when sees recto. */ function back2front_picture_content($content, $element_info) { @@ -119,7 +123,7 @@ function back2front_picture_modify() /* SAVE VALUES */ if (isset($_POST['b2f_submit'])) { - /* catch all verso and recto ids and original categories */ + /* catch all back (verso) and front (recto) ids and original categories */ $query = 'SELECT * FROM '.B2F_TABLE.';'; $result = pwg_query($query); @@ -143,10 +147,10 @@ function back2front_picture_modify() } unset($rectos, $versos, $cats); - /* picture is verso */ + /* picture is a back (verso) */ if (isset($_POST['b2f_is_verso'])) { - /* verso don't exists */ + /* back (verso) doesn't exists */ if (!picture_exists($_POST['b2f_front_id'])) { array_push($page['errors'], sprintf( @@ -154,12 +158,12 @@ function back2front_picture_modify() $_POST['b2f_front_id'] )); } - /* verso same as recto */ + /* back (verso) is same as front (recto) */ else if ($_POST['b2f_front_id'] == $_GET['image_id']) { array_push($page['errors'], l10n('Backside and frontside can\'t be the same picture')); } - /* recto has already a verso */ + /* front (recto) already has a back (verso) */ else if (in_array($_POST['b2f_front_id'], array_keys($all_recto_verso)) && $all_recto_verso[$_POST['b2f_front_id']] != $_GET['image_id']) { $recto_current_verso['id'] = $all_recto_verso[$_POST['b2f_front_id']]; @@ -171,7 +175,7 @@ function back2front_picture_modify() ''.$recto_current_verso['id'].'' )); } - /* recto is already a verso */ + /* front (recto) is already a back (verso) */ else if (in_array($_POST['b2f_front_id'], array_values($all_recto_verso))) { $recto_is_verso['id'] = $_POST['b2f_front_id']; @@ -185,7 +189,8 @@ function back2front_picture_modify() /* everything is fine */ else { - // move the verso - if first save + // move the back (verso) - if first save + if (isset($_POST['b2f_move_verso']) && (!array_key_exists($_GET['image_id'], $verso_cats) || $verso_cats[$_GET['image_id']] == null)) { // get current categories @@ -201,7 +206,7 @@ function back2front_picture_modify() $verso_categories = isset($verso_cats[$_GET['image_id']]) ? $verso_cats[$_GET['image_id']] : implode(',',$verso_categories); $template->assign('B2F_MOVE_VERSO', 'checked="checked"'); } - // restore the verso - if precedently moved + // restore the back (verso) - if precedently moved else if (!isset($_POST['b2f_move_verso']) && array_key_exists($_GET['image_id'], $verso_cats) && $verso_cats[$_GET['image_id']] != null) { $item['verso_id'] = $_GET['image_id']; @@ -211,14 +216,14 @@ function back2front_picture_modify() $verso_categories = 'NULL'; $template->assign('B2F_MOVE_VERSO', ''); } - // leave the verso + // leave the back (verso) else { $verso_categories = isset($verso_cats[$_GET['image_id']]) ? $verso_cats[$_GET['image_id']] : 'NULL'; $template->assign('B2F_MOVE_VERSO', isset($verso_cats[$_GET['image_id']]) ? 'checked="checked"' : ''); } - // insert or update verso associations + // insert or update back (verso) associations $query = ' INSERT INTO '.B2F_TABLE.' VALUES( @@ -246,10 +251,10 @@ function back2front_picture_modify() )); } } - /* picture isn't verso */ + /* picture isn't back (verso) */ else { - /* search if it was a verso */ + /* search if it was a back (verso) */ $query = ' SELECT categories FROM '.B2F_TABLE.' @@ -273,9 +278,8 @@ function back2front_picture_modify() /* GET SAVED VALUES */ if ($template->get_template_vars('B2F_IS_VERSO') == null) { - $template->assign('B2F_MOVE_VERSO', 'checked="checked"'); - /* is the picture a verso ? */ + /* is the picture a back (verso) ? */ $query = ' SELECT image_id, categories FROM '.B2F_TABLE.' @@ -286,14 +290,16 @@ function back2front_picture_modify() if (pwg_db_num_rows($result)) { list($recto_id, $cats) = pwg_db_fetch_row($result); - + $backside_hidden = (isset($cats) && !empty($cats) && $cats != "NULL"); $template->assign(array( 'B2F_IS_VERSO' => 'checked="checked"', 'B2F_FRONT_ID' => $recto_id, - 'B2F_MOVE_VERSO' => $cats != NULL ? 'checked="checked"' : '', + 'B2F_MOVE_VERSO' => $backside_hidden ? 'checked="checked"' : '' )); } - /* is the picture a front ? */ + /* The image is either a front (recto) for some back (verso), + ** or is neither a front (recto) nor a back (verso). + */ else { $query = ' @@ -303,6 +309,8 @@ function back2front_picture_modify() ;'; $result = pwg_query($query); + // If there are rows, then the image is the front (recto) for some back (verso). + // This logic will simply display the back (verso) image id# in the template. if (pwg_db_num_rows($result)) { $item = pwg_db_fetch_assoc($result); @@ -311,6 +319,16 @@ function back2front_picture_modify() 'B2F_VERSO_ID' => $item['verso_id'], 'B2F_VERSO_URL' => get_root_url().'admin.php?page=photo-'.$item['verso_id'], )); + } + // Otherwise this image is neither a front (recto) nor a back (verso). + // This logic provides the options of making it a back (verso) to some other front (recto) in the template. + else + { + $template->assign(array( + //'B2F_IS_VERSO' => '', // The template checks if this is unset and creates an *unchecked* box for "this is a backside". + 'B2F_FRONT_ID' => '', + 'B2F_MOVE_VERSO' => '', + )); } } } diff --git a/language/en_UK/plugin.lang.php b/language/en_UK/plugin.lang.php index e314236..bed9b7a 100644 --- a/language/en_UK/plugin.lang.php +++ b/language/en_UK/plugin.lang.php @@ -18,17 +18,17 @@ $lang['Seperate the two labels with the | symbol. Leave blank to use default translation.'] = 'Separate the two labels with the | symbol. Leave blank to use default translation.'; -$lang['This picture is a backside...'] = 'This picture is a backside...'; -$lang['...of the picture n°'] = '...of the picture n°'; -$lang['Backside management'] = 'Backside management'; -$lang['Hide backside from albums'] = 'Hide backside from albums'; -$lang['This picture has a backside :'] = 'This picture has a backside: '; +$lang['This picture is a backside...'] = 'This image is a backside...'; +$lang['...of the picture n°'] = 'of image id: '; +$lang['Backside management'] = 'Backside Management'; +$lang['Hide backside from albums'] = 'Hide backside image from albums'; +$lang['This picture has a backside :'] = 'This image has backside image id: '; -$lang['Backside and frontside can\'t be the same picture'] = 'Backside and frontside can\'t be the same picture'; -$lang['The picture n°%d has already a backside : %s'] = 'The picture n°%d has already a backside: %s'; -$lang['The picture n°%s is already a backside'] = 'The picture n°%s is already a backside'; -$lang['This picture is now the backside of the picture n°%s'] = 'This picture is now the backside of the picture n°%s'; -$lang['Unknown id %d for frontside picture'] = 'Unknown id %d for frontside picture'; -$lang['This picture is no longer a backside'] = 'This picture is no longer a backside'; +$lang['Backside and frontside can\'t be the same picture'] = 'Backside and frontside images can\'t be the same'; +$lang['The picture n°%d has already a backside : %s'] = 'Image id=%d already has a backside: %s'; +$lang['The picture n°%s is already a backside'] = 'Image id=%s is already a backside'; +$lang['This picture is now the backside of the picture n°%s'] = 'This image is now the backside of image id = %s'; +$lang['Unknown id %d for frontside picture'] = 'Unknown image id %d for frontside image'; +$lang['This picture is no longer a backside'] = 'This image is no longer a backside'; ?> \ No newline at end of file diff --git a/pem_metadata.txt b/pem_metadata.txt new file mode 100644 index 0000000..f6e4ea5 --- /dev/null +++ b/pem_metadata.txt @@ -0,0 +1,4 @@ +File automatically created from SVN or Git repository. + +URL: https://github.com/Piwigo/Piwigo-Back2Front +Revision: b65e92aca1f2ac414a2cfdc0472a5d42e93ce87b (Tue Nov 30 15:07:57 2021 +0100) \ No newline at end of file diff --git a/template/picture_modify.tpl b/template/picture_modify.tpl index 1d83ba1..ef4a1bb 100644 --- a/template/picture_modify.tpl +++ b/template/picture_modify.tpl @@ -22,18 +22,18 @@ $(document).ready(function () {ldelim} {else} + - - - + + - +
{'This picture is a backside...'|@translate}
{'...of the picture n°'|@translate}{'...of the picture n°'|@translate}
{'Hide backside from albums'|@translate} {'Hide backside from albums'|@translate}