galleries
4 months ago
providers
4 months ago
settings
4 months ago
class-fast-image.php
2 years ago
class-folders.php
4 months ago
class-frontend.php
4 months ago
class-galleries.php
4 months ago
class-multilang.php
2 years ago
class-remote-library-api.php
4 months ago
class-remote-library.php
4 months ago
class-settings-api.php
4 months ago
class-settings-data.php
4 months ago
class-settings-pages.php
4 months ago
class-settings.php
4 months ago
class-tour.php
4 months ago
class-welcome.php
4 months ago
class-widgets.php
2 years ago
functions.php
3 years ago
functions.php
183 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Responsive Lightbox public functions |
| 4 | * |
| 5 | * Functions available for users and developers. May not be replaced. |
| 6 | * |
| 7 | * @since 2.0 |
| 8 | */ |
| 9 | if ( ! defined( 'ABSPATH' ) ) |
| 10 | exit; |
| 11 | |
| 12 | /** |
| 13 | * Display gallery using shortcode. |
| 14 | * |
| 15 | * @param array $args Shortcode arguments |
| 16 | * @return void |
| 17 | */ |
| 18 | function rl_gallery( $args = [] ) { |
| 19 | $defaults = [ |
| 20 | 'id' => 0 |
| 21 | ]; |
| 22 | |
| 23 | // merge defaults with arguments |
| 24 | $args = array_merge( $defaults, $args ); |
| 25 | |
| 26 | // parse id |
| 27 | $args['id'] = (int) $args['id']; |
| 28 | |
| 29 | // is it gallery? |
| 30 | if ( get_post_type( $args['id'] ) === 'rl_gallery' ) |
| 31 | echo do_shortcode( '[rl_gallery id="' . (int) $args['id'] . '"]' ); |
| 32 | else |
| 33 | echo '[rl_gallery id="' . (int) $args['id'] . '"]'; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Get gallery shortcode images - wrapper. |
| 38 | * |
| 39 | * @param array $args Gallery arguments |
| 40 | * @return array |
| 41 | */ |
| 42 | function rl_get_gallery_shortcode_images( $args ) { |
| 43 | return Responsive_Lightbox()->frontend->get_gallery_shortcode_images( $args ); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Get gallery fields - wrapper. |
| 48 | * |
| 49 | * @param string $type Gallery type |
| 50 | * @return array |
| 51 | */ |
| 52 | function rl_get_gallery_fields( $type ) { |
| 53 | return Responsive_Lightbox()->frontend->get_gallery_fields( $type ); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Get gallery fields combined with shortcode attributes - wrapper. |
| 58 | * |
| 59 | * @param array $fields Gallery fields |
| 60 | * @param array $shortcode_atts Gallery shortcode attributes |
| 61 | * @param bool $gallery Whether is it rl_gallery shortcode |
| 62 | * @return array |
| 63 | */ |
| 64 | function rl_get_gallery_fields_atts( $fields, $shortcode_atts, $gallery = true ) { |
| 65 | return Responsive_Lightbox()->frontend->get_gallery_fields_atts( $fields, $shortcode_atts, $gallery ); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Get gallery images - wrapper. |
| 70 | * |
| 71 | * @param int $gallery_id Gallery ID |
| 72 | * @param array $args Gellery args |
| 73 | * @return array |
| 74 | */ |
| 75 | function rl_get_gallery_images( $gallery_id, $args ) { |
| 76 | if ( did_action( 'init' ) ) |
| 77 | return Responsive_Lightbox()->galleries->get_gallery_images( $gallery_id, $args ); |
| 78 | else |
| 79 | return []; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Add lightbox to images, galleries and videos. |
| 84 | * |
| 85 | * @param string $content HTML content |
| 86 | * @return string |
| 87 | */ |
| 88 | function rl_add_lightbox( $content ) { |
| 89 | return Responsive_Lightbox()->frontend->add_lightbox( $content ); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Get attachment id by URL. |
| 94 | * |
| 95 | * @param string $url Image URL |
| 96 | * @return int |
| 97 | */ |
| 98 | function rl_get_attachment_id_by_url( $url ) { |
| 99 | return Responsive_Lightbox()->frontend->get_attachment_id_by_url( $url ); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Get image size by URL. |
| 104 | * |
| 105 | * @param string $url Image URL |
| 106 | * @return array |
| 107 | */ |
| 108 | function rl_get_image_size_by_url( $url ) { |
| 109 | return Responsive_Lightbox()->frontend->get_image_size_by_url( $url ); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Get current lightbox script. |
| 114 | * |
| 115 | * @return string |
| 116 | */ |
| 117 | function rl_get_lightbox_script() { |
| 118 | return Responsive_Lightbox()->get_data( 'current_script' ); |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Set current lightbox script. |
| 123 | * |
| 124 | * @param string $script |
| 125 | * @return bool |
| 126 | */ |
| 127 | function rl_set_lightbox_script( $script ) { |
| 128 | return Responsive_Lightbox()->set_lightbox_script( $script ); |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Check whether lightbox supports specified type(s). |
| 133 | * |
| 134 | * @param string|array $type Lightbox support type(s), leave empty to get all supported features |
| 135 | * @param string $compare_mode |
| 136 | * @return bool|array |
| 137 | */ |
| 138 | function rl_current_lightbox_supports( $type = '', $compare_mode = 'AND' ) { |
| 139 | // get main instance |
| 140 | $rl = Responsive_Lightbox(); |
| 141 | |
| 142 | // get current script |
| 143 | $script = $rl->get_data( 'current_script' ); |
| 144 | |
| 145 | // get scripts |
| 146 | $scripts = $rl->settings->get_data( 'scripts' ); |
| 147 | |
| 148 | // valid script? |
| 149 | if ( array_key_exists( $script, $scripts ) && array_key_exists( 'supports', $scripts[$script] ) ) { |
| 150 | if ( ! empty( $type ) ) { |
| 151 | // multitype? |
| 152 | if ( is_array( $type ) ) { |
| 153 | // filter types |
| 154 | $type = array_filter( $type ); |
| 155 | |
| 156 | if ( empty( $type ) ) |
| 157 | return false; |
| 158 | |
| 159 | $supports = ( $compare_mode === 'AND' ); |
| 160 | |
| 161 | foreach ( $type as $_type ) { |
| 162 | // single type required |
| 163 | if ( $compare_mode === 'OR' ) { |
| 164 | if ( in_array( $_type, $scripts[$script]['supports'], true ) ) |
| 165 | return true; |
| 166 | // all types required |
| 167 | } else { |
| 168 | if ( ! in_array( $_type, $scripts[$script]['supports'], true ) ) |
| 169 | return false; |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | return $supports; |
| 174 | // single type |
| 175 | } else |
| 176 | return in_array( $type, $scripts[$script]['supports'], true ); |
| 177 | // return all supported features |
| 178 | } else |
| 179 | return $scripts[$script]['supports']; |
| 180 | } |
| 181 | |
| 182 | return false; |
| 183 | } |