Skip to content

Commit

Permalink
Merge pull request #1 from canalnoises/Fix-Issue-2-Back2Front-Warning…
Browse files Browse the repository at this point in the history
…-Messages-

Fix Issue Piwigo#2
  • Loading branch information
canalnoises authored Jan 3, 2024
2 parents e9aed91 + c13a83c commit 4acc3eb
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 33 deletions.
54 changes: 36 additions & 18 deletions include/Back2Front.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);

Expand All @@ -143,23 +147,23 @@ 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(
l10n('Unknown id %d for frontside picture'),
$_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']];
Expand All @@ -171,7 +175,7 @@ function back2front_picture_modify()
'<a href="'.$recto_current_verso['link'].'">'.$recto_current_verso['id'].'</a>'
));
}
/* 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'];
Expand All @@ -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
Expand All @@ -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'];
Expand All @@ -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(
Expand Down Expand Up @@ -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.'
Expand All @@ -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.'
Expand All @@ -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 = '
Expand All @@ -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);
Expand All @@ -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' => '',
));
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions language/en_UK/plugin.lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

?>
4 changes: 4 additions & 0 deletions pem_metadata.txt
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 4 additions & 4 deletions template/picture_modify.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ $(document).ready(function () {ldelim}
{else}
<table style="min-width:400px;">
<tr>
<td><input type="checkbox" name="b2f_is_verso" {if isset($B2F_IS_VERSO)}{$B2F_IS_VERSO}"{/if}></td>
<td><b>{'This picture is a backside...'|@translate}</b></td>
<td style="width:70px"><input type="checkbox" name="b2f_is_verso" {$B2F_IS_VERSO}></td>
</tr>
<tr class="frontside_param" {if !isset($B2F_IS_VERSO)}style="display:none;"{/if}>
<td><b>{'...of the picture n°'|@translate}</b></td>
<td><input type="text" size="4" name="b2f_front_id" value="{$B2F_FRONT_ID}"></td>
<td></td>
<td><b>{'...of the picture n°'|@translate}</b><input type="text" size="4" name="b2f_front_id" value="{$B2F_FRONT_ID}"></td>
</tr>
<tr class="frontside_param" {if !isset($B2F_IS_VERSO)}style="display:none;"{/if}>
<td><b>{'Hide backside from albums'|@translate}</b></td>
<td><input type="checkbox" name="b2f_move_verso" {$B2F_MOVE_VERSO}></td>
<td><b>{'Hide backside from albums'|@translate}</b></td>
</tr>
</table>
Expand Down

0 comments on commit 4acc3eb

Please sign in to comment.