Photo Gallery by Envira – Responsive Image Gallery for WordPress - Version 1.5.6.2

Version Description

Download this release

Release Info

Developer chrisakelley
Plugin Icon 128x128 Photo Gallery by Envira – Responsive Image Gallery for WordPress
Version 1.5.6.2
Comparing to
See all releases

Code changes from version 1.5.6.1 to 1.5.6.2

envira-gallery-lite.php CHANGED
@@ -5,7 +5,7 @@
5
  * Description: Envira Gallery is best responsive WordPress gallery plugin. This is the lite version.
6
  * Author: Thomas Griffin
7
  * Author URI: http://enviragallery.com
8
- * Version: 1.5.6.1
9
  * Text Domain: envira-gallery
10
  *
11
  * Envira Gallery is free software: you can redistribute it and/or modify
@@ -53,7 +53,7 @@ class Envira_Gallery_Lite {
53
  *
54
  * @var string
55
  */
56
- public $version = '1.5.6.1';
57
 
58
  /**
59
  * The name of the plugin.
5
  * Description: Envira Gallery is best responsive WordPress gallery plugin. This is the lite version.
6
  * Author: Thomas Griffin
7
  * Author URI: http://enviragallery.com
8
+ * Version: 1.5.6.2
9
  * Text Domain: envira-gallery
10
  *
11
  * Envira Gallery is free software: you can redistribute it and/or modify
53
  *
54
  * @var string
55
  */
56
+ public $version = '1.5.6.2';
57
 
58
  /**
59
  * The name of the plugin.
includes/global/shortcode.php CHANGED
@@ -1355,178 +1355,238 @@ class Envira_Gallery_Shortcode {
1355
 
1356
  }
1357
 
1358
- /**
1359
- * Helper method to retrieve the proper image src attribute based on gallery settings.
1360
- *
1361
- * @since 1.0.0
1362
- *
1363
- * @param int $id The image attachment ID to use.
1364
- * @param array $item Gallery item data.
1365
- * @param array $data The gallery data to use for retrieval.
1366
- * @param bool $mobile Whether or not to retrieve the mobile image.
1367
- * @param bool $retina Whether to return a retina sized image.
1368
- * @return string The proper image src attribute for the image.
1369
- */
1370
- public function get_image_src( $id, $item, $data, $mobile = false, $retina = false ) {
1371
-
1372
- // Detect if user is on a mobile device - if so, override $mobile flag which may be manually set
1373
- // by out of date addons or plugins
1374
- if ( $this->get_config( 'mobile', $data ) ) {
1375
- $mobile = envira_mobile_detect()->isMobile();
1376
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1377
 
1378
- // Define variable
1379
- $src = false;
1380
 
1381
- // If this image is an instagram, we grab the src and don't use the $id
1382
- // otherwise using the $id refers to a postID in the databaes and has been known
1383
- // at times to pull up the wrong thumbnail instead of the instagram one
1384
 
1385
- $instagram = false;
1386
 
1387
- if ( !empty($item['src']) && strpos( $item['src'], 'cdninstagram' ) !== false ) :
1388
- // using 'cdninstagram' because it seems all urls contain it - but be watchful in the future
1389
- $instagram = true;
1390
- $src = $item['src'];
1391
- $image = $item['src'];
1392
- endif;
1393
-
1394
- $image_size = $this->get_config( 'image_size', $data );
1395
-
1396
- if ( !$src ) :
1397
-
1398
- // Check if this Gallery uses a WordPress defined image size
1399
- if ( $image_size != 'default' && ! $retina ) {
1400
- // If image size is envira_gallery_random, get a random image size.
1401
- if ( $image_size == 'envira_gallery_random' ) {
1402
-
1403
- // Get random image sizes that have been chosen for this Gallery.
1404
- $image_sizes_random = (array) $this->get_config( 'image_sizes_random', $data );
1405
-
1406
- if ( count( $image_sizes_random ) == 0 ) {
1407
- // The user didn't choose any image sizes - use them all.
1408
- $wordpress_image_sizes = $this->common->get_image_sizes( true );
1409
- $wordpress_image_size_random_key = array_rand( $wordpress_image_sizes, 1 );
1410
- $image_size = $wordpress_image_sizes[ $wordpress_image_size_random_key ]['value'];
1411
- } else {
1412
- $wordpress_image_size_random_key = array_rand( $image_sizes_random, 1 );
1413
- $image_size = $image_sizes_random[ $wordpress_image_size_random_key ];
1414
- }
1415
 
1416
- // Get the random WordPress defined image size
1417
- $src = wp_get_attachment_image_src( $id, $image_size );
1418
- } else {
1419
- // Get the requested WordPress defined image size
1420
- $src = wp_get_attachment_image_src( $id, $image_size );
1421
- }
1422
- } else {
1423
-
1424
- $row_height = $retina ? intval( $this->get_config( 'justified_row_height', $data ) ) * 2 : intval( $this->get_config( 'justified_row_height', $data ) );
1425
- $crop = $this->get_config( 'crop', $data );
1426
-
1427
- //200 fixes the 4:3 crop issue
1428
- if ( $row_height <= 200 && ! $crop ){
1429
-
1430
- // Get the full image
1431
- $src = apply_filters( 'envira_gallery_retina_image_src', wp_get_attachment_image_src( $id, 'medium' ), $id, $item, $data, $this->is_mobile );
1432
-
1433
- } elseif ( $row_height <= 640 && ! $crop ){
1434
-
1435
- $src = apply_filters( 'envira_gallery_retina_image_src', wp_get_attachment_image_src( $id, 'large' ), $id, $item, $data, $this->is_mobile );
1436
-
1437
- }else{
1438
-
1439
- $src = apply_filters( 'envira_gallery_retina_image_src', wp_get_attachment_image_src( $id, 'full' ), $id, $item, $data, $this->is_mobile );
1440
-
1441
- }
1442
-
1443
- }
1444
-
1445
- endif;
1446
-
1447
- // Check if this returned an image
1448
- if ( ! $src ) {
1449
- // Fallback to the $item's image source
1450
- $image = $item['src'];
1451
- } else if ( ! $instagram ) {
1452
- $image = $src[0];
1453
- }
1454
-
1455
- // If we still don't have an image at this point, something went wrong
1456
- if ( ! isset( $image ) ) {
1457
- return apply_filters( 'envira_gallery_no_image_src', $item['link'], $id, $item, $data );
1458
- }
1459
-
1460
- // Prep our indexable images.
1461
- if ( $image && ! $mobile ) {
1462
- $this->index[ $data['id'] ][ $id ] = array(
1463
- 'src' => $image,
1464
- 'alt' => ! empty( $item['alt'] ) ? $item['alt'] : ''
1465
- );
1466
- }
1467
-
1468
- // If the image size is a WordPress size and we're not requesting a retina image
1469
- // we don't need to resize or crop anything.
1470
- if ( $image_size != 'default' && ! $retina ) {
1471
- // Return the image
1472
- return apply_filters( 'envira_gallery_image_src', $image, $id, $item, $data );
1473
- }
1474
-
1475
- // If the image size is default (i.e. the user has input their own custom dimensions in the Gallery),
1476
- // we may need to resize the image now
1477
- // This is safe to call every time, as resize_image() will check if the image already exists, preventing thumbnails
1478
- // from being generated every single time.
1479
- $type = $mobile ? 'mobile' : 'crop'; // 'crop' is misleading here - it's the key that stores the thumbnail width + height
1480
- $args = array(
1481
- 'position' => 'c',
1482
- 'width' => $this->get_config( $type . '_width', $data ),
1483
- 'height' => $this->get_config( $type . '_height', $data ),
1484
- 'quality' => 100,
1485
- 'retina' => $retina,
1486
- );
1487
-
1488
- // If we're requesting a retina image, and the gallery uses a registered WordPress image size,
1489
- // we need use the width and height of that registered WordPress image size - not the gallery's
1490
- // image width and height, which are hidden settings.
1491
- if ( $image_size != 'default' && $retina ) {
1492
- // Find WordPress registered image size
1493
- $wordpress_image_sizes = $this->common->get_image_sizes( true ); // true = WordPress only image sizes (excludes random)
1494
-
1495
- foreach ( $wordpress_image_sizes as $size ) {
1496
- if ( $size['value'] !== $image_size ) {
1497
- continue;
1498
- }
1499
-
1500
- // We found the image size. Use its dimensions
1501
- $args['width'] = $size['width'];
1502
- $args['height'] = $size['height'];
1503
- break;
1504
-
1505
- }
1506
- }
1507
-
1508
- // Filter
1509
- $args = apply_filters( 'envira_gallery_crop_image_args', $args);
1510
-
1511
- $resized_image = $this->common->resize_image( $image, $args['width'], $args['height'], $this->get_config( 'crop', $data ), $args['position'], $args['quality'], $args['retina'], $data );
1512
-
1513
- // If there is an error, possibly output error message and return the default image src.
1514
- if ( is_wp_error( $resized_image ) ) {
1515
- // If WP_DEBUG is enabled, and we're logged in, output an error to the user
1516
- if ( defined( 'WP_DEBUG' ) && WP_DEBUG && is_user_logged_in() ) {
1517
- echo '<pre>Envira: Error occured resizing image (these messages are only displayed to logged in WordPress users):<br />';
1518
- echo 'Error: ' . $resized_image->get_error_message() . '<br />';
1519
- echo 'Image: ' . $image . '<br />';
1520
- echo 'Args: ' . var_export( $args, true ) . '</pre>';
1521
- }
1522
-
1523
- // Return the non-cropped image as a fallback.
1524
- return apply_filters( 'envira_gallery_image_src', $image, $id, $item, $data );
1525
- } else {
1526
- return apply_filters( 'envira_gallery_image_src', $resized_image, $id, $item, $data );
1527
- }
1528
-
1529
- }
1530
 
1531
  /**
1532
  * Helper method to retrieve the proper gallery toolbar template.
1355
 
1356
  }
1357
 
1358
+ /**
1359
+ * Helper method to retrieve the proper image src attribute based on gallery settings.
1360
+ *
1361
+ * @since 1.0.0
1362
+ *
1363
+ * @param int $id The image attachment ID to use.
1364
+ * @param array $item Gallery item data.
1365
+ * @param array $data The gallery data to use for retrieval.
1366
+ * @param bool $this->is_mobile Whether or not to retrieve the mobile image.
1367
+ * @param bool $retina Whether to return a retina sized image.
1368
+ * @return string The proper image src attribute for the image.
1369
+ */
1370
+ public function get_image_src( $id, $item, $data, $mobile = false, $retina = false ) {
1371
+
1372
+ // Define variable
1373
+ $src = false;
1374
+
1375
+ // If this image is an instagram, we grab the src and don't use the $id
1376
+ // otherwise using the $id refers to a postID in the database and has been known
1377
+ // at times to pull up the wrong thumbnail instead of the instagram one
1378
+
1379
+ $instagram = false;
1380
+
1381
+ if ( !empty($item['src']) && strpos( $item['src'], 'cdninstagram' ) !== false ) :
1382
+ // using 'cdninstagram' because it seems all urls contain it - but be watchful in the future
1383
+ $instagram = true;
1384
+ $src = $item['src'];
1385
+ $image = $item['src'];
1386
+ endif;
1387
+
1388
+ $image_size = $this->get_config( 'image_size', $data );
1389
+
1390
+ if ( !$src ) :
1391
+
1392
+ // Check if this Gallery uses a WordPress defined image size
1393
+ if ( $image_size != 'default' && ! $retina ) {
1394
+ // If image size is envira_gallery_random, get a random image size.
1395
+ if ( $image_size == 'envira_gallery_random' ) {
1396
+
1397
+ // Get random image sizes that have been chosen for this Gallery.
1398
+ $image_sizes_random = (array) $this->get_config( 'image_sizes_random', $data );
1399
+
1400
+ if ( count( $image_sizes_random ) == 0 ) {
1401
+ // The user didn't choose any image sizes - use them all.
1402
+ $wordpress_image_sizes = $this->common->get_image_sizes( true );
1403
+ $wordpress_image_size_random_key = array_rand( $wordpress_image_sizes, 1 );
1404
+ $image_size = $wordpress_image_sizes[ $wordpress_image_size_random_key ]['value'];
1405
+ } else {
1406
+ $wordpress_image_size_random_key = array_rand( $image_sizes_random, 1 );
1407
+ $image_size = $image_sizes_random[ $wordpress_image_size_random_key ];
1408
+ }
1409
+
1410
+ // Get the random WordPress defined image size
1411
+ $src = wp_get_attachment_image_src( $id, $image_size );
1412
+ } else {
1413
+ // Get the requested WordPress defined image size
1414
+ $src = wp_get_attachment_image_src( $id, $image_size );
1415
+ }
1416
+ } else {
1417
+
1418
+ if ( ! $retina ){
1419
+
1420
+ $isize = $this->find_clostest_size( $data ) != '' ? $this->find_clostest_size( $data ) : 'full';
1421
+ $src = apply_filters( 'envira_gallery_retina_image_src', wp_get_attachment_image_src( $id, $isize ), $id, $item, $data, $this->is_mobile );
1422
+
1423
+ }else{
1424
+ $src = apply_filters( 'envira_gallery_retina_image_src', wp_get_attachment_image_src( $id, 'full' ), $id, $item, $data, $this->is_mobile );
1425
+ }
1426
+
1427
+
1428
+ }
1429
+
1430
+ endif;
1431
+
1432
+
1433
+ // Check if this returned an image
1434
+ if ( ! $src ) {
1435
+ // Fallback to the $item's image source
1436
+ $image = $item['src'];
1437
+ } else if ( ! $instagram ) {
1438
+ $image = $src[0];
1439
+ }
1440
+
1441
+ // If we still don't have an image at this point, something went wrong
1442
+ if ( ! isset( $image ) ) {
1443
+ return apply_filters( 'envira_gallery_no_image_src', $item['link'], $id, $item, $data );
1444
+ }
1445
+
1446
+ // Prep our indexable images.
1447
+ if ( $image && ! $this->is_mobile ) {
1448
+ $this->index[ $data['id'] ][ $id ] = array(
1449
+ 'src' => $image,
1450
+ 'alt' => ! empty( $item['alt'] ) ? $item['alt'] : ''
1451
+ );
1452
+ }
1453
+
1454
+ // If the current layout is justified/automatic
1455
+ // if the image size is a WordPress size and we're not requesting a retina image we don't need to resize or crop anything.
1456
+ if ( $image_size != 'default' && ! $retina ) {
1457
+ // if ( ( $image_size != 'default' && ! $retina ) ) {
1458
+ // Return the image
1459
+ return apply_filters( 'envira_gallery_image_src', $image, $id, $item, $data );
1460
+ }
1461
+
1462
+ // If the image size is default (i.e. the user has input their own custom dimensions in the Gallery),
1463
+ // we may need to resize the image now
1464
+ // This is safe to call every time, as resize_image() will check if the image already exists, preventing thumbnails
1465
+ // from being generated every single time.
1466
+ $type = $this->is_mobile ? 'mobile' : 'crop'; // 'crop' is misleading here - it's the key that stores the thumbnail width + height
1467
+ $args = array(
1468
+ 'position' => 'c',
1469
+ 'width' => $this->get_config( $type . '_width', $data ),
1470
+ 'height' => $this->get_config( $type . '_height', $data ),
1471
+ 'quality' => 100,
1472
+ 'retina' => $retina,
1473
+ );
1474
+
1475
+ // If we're requesting a retina image, and the gallery uses a registered WordPress image size,
1476
+ // we need use the width and height of that registered WordPress image size - not the gallery's
1477
+ // image width and height, which are hidden settings.
1478
+ if ( $image_size != 'default' && $retina ) {
1479
+ // Find WordPress registered image size
1480
+ $wordpress_image_sizes = $this->common->get_image_sizes( true ); // true = WordPress only image sizes (excludes random)
1481
+
1482
+ foreach ( $wordpress_image_sizes as $size ) {
1483
+ if ( $size['value'] !== $image_size ) {
1484
+ continue;
1485
+ }
1486
+
1487
+ // We found the image size. Use its dimensions
1488
+ $args['width'] = $size['width'];
1489
+ $args['height'] = $size['height'];
1490
+ break;
1491
+
1492
+ }
1493
+ }
1494
+
1495
+ // Filter
1496
+ $args = apply_filters( 'envira_gallery_crop_image_args', $args);
1497
+ $resized_image = $this->common->resize_image( $image, $args['width'], $args['height'], $this->get_config( 'crop', $data ), $args['position'], $args['quality'], $args['retina'], $data );
1498
+
1499
+ // If there is an error, possibly output error message and return the default image src.
1500
+ if ( is_wp_error( $resized_image ) ) {
1501
+ // If WP_DEBUG is enabled, and we're logged in, output an error to the user
1502
+ if ( defined( 'WP_DEBUG' ) && WP_DEBUG && is_user_logged_in() ) {
1503
+ echo '<pre>Envira: Error occured resizing image (these messages are only displayed to logged in WordPress users):<br />';
1504
+ echo 'Error: ' . $resized_image->get_error_message() . '<br />';
1505
+ echo 'Image: ' . $image . '<br />';
1506
+ echo 'Args: ' . var_export( $args, true ) . '</pre>';
1507
+ }
1508
+
1509
+ // Return the non-cropped image as a fallback.
1510
+ return apply_filters( 'envira_gallery_image_src', $image, $id, $item, $data );
1511
+ } else {
1512
+ return apply_filters( 'envira_gallery_image_src', $resized_image, $id, $item, $data );
1513
+ }
1514
+
1515
+ }
1516
+
1517
+ public function find_clostest_size( $data ){
1518
+
1519
+ $image_sizes = $this->get_image_sizes();
1520
+ $dimensions = $this->get_config( 'dimensions', $data );
1521
+ $width = $this->get_config( 'crop_width', $data );
1522
+ $height = $this->get_config( 'crop_height', $data );
1523
+ $match = false;
1524
+
1525
+ usort($image_sizes, function($a, $b) {
1526
+ return intval($a['width']) - intval($b['width'] );
1527
+ });
1528
+
1529
+ foreach( $image_sizes as $num ) {
1530
+
1531
+ $num['width'] = (int) $num['width'];
1532
+ $num['height'] = (int) $num['height'];
1533
+
1534
+ //skip over sizes that are smaller
1535
+ if ( $num['height'] < $height || $num['width'] < $width ){
1536
+ continue;
1537
+ }
1538
+ if ( $num['width'] > $width && $num['height'] > $height ) {
1539
+
1540
+ if ( $match === false ) {
1541
+
1542
+ $match = true;
1543
+ $size = $num['name'];
1544
+
1545
+ return $size;
1546
+ }
1547
+ }
1548
+ }
1549
+ return '';
1550
+
1551
+ }
1552
+
1553
+ public function get_image_sizes(){
1554
+
1555
+ global $_wp_additional_image_sizes;
1556
+
1557
+ $sizes = array();
1558
+ foreach ( get_intermediate_image_sizes() as $_size ) {
1559
+
1560
+ if ( in_array( $_size, array('thumbnail', 'medium', 'medium_large', 'large') ) ) {
1561
+
1562
+ if ( (bool) get_option( "{$_size}_crop" ) === true ){
1563
+
1564
+ continue;
1565
+
1566
+ }
1567
+ $sizes[ $_size ]['name'] = $_size;
1568
+ $sizes[ $_size ]['width'] = get_option( "{$_size}_size_w" );
1569
+ $sizes[ $_size ]['height'] = get_option( "{$_size}_size_h" );
1570
+ $sizes[ $_size ]['crop'] = (bool) get_option( "{$_size}_crop" );
1571
 
1572
+ } elseif ( isset( $_wp_additional_image_sizes[ $_size ] ) ) {
 
1573
 
1574
+ if( $_wp_additional_image_sizes[ $_size ]['crop'] === true ){
 
 
1575
 
1576
+ continue;
1577
 
1578
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1579
 
1580
+ $sizes[ $_size ] = array(
1581
+ 'name' => $_size,
1582
+ 'width' => $_wp_additional_image_sizes[ $_size ]['width'],
1583
+ 'height' => $_wp_additional_image_sizes[ $_size ]['height'],
1584
+ 'crop' => $_wp_additional_image_sizes[ $_size ]['crop'],
1585
+ );
1586
+ }
1587
+ }
1588
+ return $sizes;
1589
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1590
 
1591
  /**
1592
  * Helper method to retrieve the proper gallery toolbar template.
readme.txt CHANGED
@@ -185,6 +185,12 @@ Also, I'm an <a href="https://thomasgriffin.io" rel="me" title="WordPress Develo
185
 
186
  == Changelog ==
187
 
 
 
 
 
 
 
188
  = 1.5.6.1 =
189
 
190
  * Fix: Fix cases where images appear blurry with automatic layout
185
 
186
  == Changelog ==
187
 
188
+ = 1.5.6.1 =
189
+
190
+ * Fix: Improved image selection based on various settings.
191
+ * Fix: Minor bug fixes.
192
+
193
+
194
  = 1.5.6.1 =
195
 
196
  * Fix: Fix cases where images appear blurry with automatic layout