Skip to content

Commit

Permalink
No picture photo not shown within random photo plugin if photo module…
Browse files Browse the repository at this point in the history
… has no album #1210
  • Loading branch information
Fasse committed Feb 6, 2022
1 parent 5396b5f commit e367bae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
22 changes: 9 additions & 13 deletions adm_plugins/random_photo/random_photo.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,32 +79,28 @@
$albumStatement = $gDb->queryPrepared($sql, array($gCurrentOrgId));
$albumList = $albumStatement->fetchAll();

$i = 0;
$picNr = 0;
$picPath = '';
$i = 0;
$photoNr = 0;
$photoServerPath = '';
$linkText = '';
$album = new TablePhotos($gDb);

// loop, if an image is not found directly, but limit to 20 passes
while (!is_file($picPath) && $i < 20 && $albumStatement->rowCount() > 0) {
while (!is_file($photoServerPath) && $i < 20 && $albumStatement->rowCount() > 0) {
$album->setArray($albumList[mt_rand(0, $albumStatement->rowCount()-1)]);

// optionally select an image randomly
if ($plg_photos_picnr === 0) {
$picNr = mt_rand(1, (int) $album->getValue('pho_quantity'));
$photoNr = mt_rand(1, (int) $album->getValue('pho_quantity'));
} else {
$picNr = $plg_photos_picnr;
$photoNr = $plg_photos_picnr;
}

// Compose image path
$picPath = ADMIDIO_PATH . FOLDER_DATA . '/photos/' . $album->getValue('pho_begin', 'Y-m-d') . '_' . (int) $album->getValue('pho_id') . '/' . $picNr . '.jpg';
$photoServerPath = ADMIDIO_PATH . FOLDER_DATA . '/photos/' . $album->getValue('pho_begin', 'Y-m-d') . '_' . (int) $album->getValue('pho_id') . '/' . $photoNr . '.jpg';
++$i;
}

if (!is_file($picPath)) {
$picPath = THEME_PATH . '/images/no_photo_found.png';
}

if ($plg_photos_show_link && $plg_max_char_per_word > 0) {
// Wrap link text if necessary
$words = explode(' ', $album->getValue('pho_name'));
Expand All @@ -123,9 +119,9 @@

// show the photo
$photoUuid = $album->getValue('pho_uuid');
echo '<a href="'.SecurityUtils::encodeUrl(ADMIDIO_URL.FOLDER_MODULES.'/photos/photos.php', array('photo_uuid' => $photoUuid, 'photo_nr' => $picNr)).'" target="'. $plg_link_target. '"><img
echo '<a href="'.SecurityUtils::encodeUrl(ADMIDIO_URL.FOLDER_MODULES.'/photos/photos.php', array('photo_uuid' => $photoUuid, 'photo_nr' => $photoNr)).'" target="'. $plg_link_target. '"><img
class="rounded d-block w-100" alt="'.$linkText.'" title="'.$linkText.'"
src="'.SecurityUtils::encodeUrl(ADMIDIO_URL.FOLDER_MODULES.'/photos/photo_show.php', array('photo_uuid' => $photoUuid, 'photo_nr' => $picNr, 'pho_begin' => $album->getValue('pho_begin', 'Y-m-d'), 'max_width' => $plg_photos_max_width, 'max_height' => $plg_photos_max_height)).'" /></a>';
src="'.SecurityUtils::encodeUrl(ADMIDIO_URL.FOLDER_MODULES.'/photos/photo_show.php', array('photo_uuid' => $photoUuid, 'photo_nr' => $photoNr, 'pho_begin' => $album->getValue('pho_begin', 'Y-m-d'), 'max_width' => $plg_photos_max_width, 'max_height' => $plg_photos_max_height)).'" /></a>';

// optional the linked name of the album
if ($plg_photos_show_link) {
Expand Down
2 changes: 1 addition & 1 deletion adm_program/modules/photos/photo_show.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
require_once(__DIR__ . '/../../system/common.php');

// Initialize and check the parameters
$getPhotoUuid = admFuncVariableIsValid($_GET, 'photo_uuid', 'string', array('requireValue' => true));
$getPhotoUuid = admFuncVariableIsValid($_GET, 'photo_uuid', 'string');
$getPhotoNr = admFuncVariableIsValid($_GET, 'photo_nr', 'int');
$getMaxWidth = admFuncVariableIsValid($_GET, 'max_width', 'int', array('defaultValue' => 0));
$getMaxHeight = admFuncVariableIsValid($_GET, 'max_height', 'int', array('defaultValue' => 0));
Expand Down

0 comments on commit e367bae

Please sign in to comment.