abilities
1 day ago
admin
1 day ago
compatibility
1 day ago
extensions
1 day ago
foopluginbase
1 day ago
public
1 day ago
thumbs
1 day ago
asset-manifest.php
1 day ago
class-attachment-filters.php
1 day ago
class-command-palette.php
1 day ago
class-foogallery-animated-gif-support.php
1 day ago
class-foogallery-attachment-custom-class.php
1 day ago
class-foogallery-attachment-filename.php
1 day ago
class-foogallery-attachment-type.php
1 day ago
class-foogallery-attachment.php
1 day ago
class-foogallery-cache.php
1 day ago
class-foogallery-common-fields.php
1 day ago
class-foogallery-crop-position.php
1 day ago
class-foogallery-datasource-media_library.php
1 day ago
class-foogallery-debug.php
1 day ago
class-foogallery-delayed-runtime-loader.php
1 day ago
class-foogallery-extensions-compatibility.php
1 day ago
class-foogallery-force-https.php
1 day ago
class-foogallery-lazyload.php
1 day ago
class-foogallery-license-constant-handler.php
1 day ago
class-foogallery-lightbox.php
1 day ago
class-foogallery-no-javascript-fallback.php
1 day ago
class-foogallery-paging.php
1 day ago
class-foogallery-password-protect.php
1 day ago
class-foogallery-sitemaps.php
1 day ago
class-foogallery-widget.php
1 day ago
class-foogallery.php
1 day ago
class-gallery-advanced-settings.php
1 day ago
class-il8n.php
1 day ago
class-override-thumbnail.php
1 day ago
class-posttypes.php
1 day ago
class-previews.php
1 day ago
class-retina.php
1 day ago
class-thumbnail-dimensions.php
1 day ago
class-thumbnails.php
1 day ago
class-version-check.php
1 day ago
constants.php
1 day ago
functions.php
1 day ago
gallery-management-functions.php
1 day ago
includes.php
1 day ago
index.php
1 day ago
render-functions.php
1 day ago
class-foogallery-paging.php
544 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | /** |
| 8 | * Class used to handle paging for gallery templates |
| 9 | */ |
| 10 | if ( ! class_exists( 'FooGallery_Paging' ) ) { |
| 11 | |
| 12 | class FooGallery_Paging { |
| 13 | |
| 14 | function __construct() { |
| 15 | add_action( 'plugins_loaded', array( $this, 'load_feature' ) ); |
| 16 | } |
| 17 | |
| 18 | function load_feature() { |
| 19 | // Register paging field definitions in every request context so |
| 20 | // non-admin consumers, including abilities, can resolve and save |
| 21 | // layout settings against the same schema as wp-admin. |
| 22 | add_filter( 'foogallery_override_gallery_template_fields', array( $this, 'add_paging_fields' ), 10, 2 ); |
| 23 | |
| 24 | add_action( 'foogallery_located_template', array( $this, 'determine_paging' ), 10, 1 ); |
| 25 | |
| 26 | //add the paging options to the gallery container |
| 27 | add_filter( 'foogallery_build_container_data_options', array( $this, 'add_paging_data_options' ), 20, 3 ); |
| 28 | add_filter( 'foogallery_build_container_mobile_data_options', array( $this, 'add_mobile_paging_data_options' ), 20, 3 ); |
| 29 | |
| 30 | //limit the number of attachments returned when rendering a gallery if paging is enabled |
| 31 | add_filter( 'foogallery_gallery_attachments_override_for_rendering', array( $this, 'attachments_override' ), 10, 3 ); |
| 32 | |
| 33 | //output pagination placeholders |
| 34 | add_action( 'foogallery_loaded_template_before', array( $this, 'output_pagination_placeholders_before' ), 20, 1 ); |
| 35 | add_action( 'foogallery_loaded_template_after', array( $this, 'output_pagination_placeholders_after' ), 10, 1 ); |
| 36 | |
| 37 | //output a script block with the rest of the attachments as json |
| 38 | add_action( 'foogallery_loaded_template_after', array( $this, 'output_paging_script_block' ), 90, 1 ); |
| 39 | |
| 40 | add_filter( 'foogallery_attachment_html_item_classes', array( $this, 'hide_item_for_html_output' ), 10, 3 ); |
| 41 | |
| 42 | add_filter( 'foogallery_attachment_get_posts_args', array( $this, 'add_paging_query_args' ), 10, 3 ); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Add paging query args to the attachment query |
| 47 | * |
| 48 | * @param $args |
| 49 | * |
| 50 | * @return mixed |
| 51 | */ |
| 52 | function add_paging_query_args( $args ) { |
| 53 | global $current_foogallery_arguments; |
| 54 | global $current_foogallery; |
| 55 | |
| 56 | if ( isset( $current_foogallery_arguments['page'] ) ) { |
| 57 | $args['page'] = $args['paged'] = intval( $current_foogallery_arguments['page'] ); |
| 58 | } |
| 59 | |
| 60 | if ( isset( $current_foogallery_arguments['posts_per_page'] ) ) { |
| 61 | $args['posts_per_page'] = intval( $current_foogallery_arguments['posts_per_page'] ); |
| 62 | } |
| 63 | |
| 64 | $posts_per_page = isset( $args['posts_per_page'] ) ? intval( $args['posts_per_page'] ) : 0; |
| 65 | |
| 66 | //check if no posts per page is set |
| 67 | if ( isset( $current_foogallery_arguments['page'] ) && $posts_per_page <= 0 ) { |
| 68 | $this->determine_paging( $current_foogallery ); |
| 69 | if ( foogallery_current_gallery_has_cached_value('paging' ) ) { |
| 70 | $paging_options = foogallery_current_gallery_get_cached_value( 'paging' ); |
| 71 | $page_size = intval( $paging_options['size'] ); |
| 72 | $args['posts_per_page'] = $page_size; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | return $args; |
| 77 | } |
| 78 | |
| 79 | function hide_item_for_html_output( $classes, $foogallery_attachment, $args ) { |
| 80 | if ( isset( $foogallery_attachment->class ) ) { |
| 81 | $classes[] = $foogallery_attachment->class; |
| 82 | } |
| 83 | return $classes; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Determine if the gallery supports paging and set a cached value for all paging options on the gallery for later use |
| 88 | * |
| 89 | * @param $foogallery |
| 90 | */ |
| 91 | function determine_paging( $foogallery ) { |
| 92 | if ( foogallery_current_gallery_check_template_has_supported_feature( 'paging_support') ) { |
| 93 | |
| 94 | //check if we have arguments from the shortcode and override the saved settings |
| 95 | $paging = foogallery_gallery_template_setting( 'paging_type', '' ); |
| 96 | |
| 97 | if ( '' !== $paging ) { |
| 98 | $paging_position = foogallery_gallery_template_setting( 'paging_position', 'both' ); |
| 99 | $paging_theme = foogallery_gallery_template_setting( 'paging_theme', '' ); |
| 100 | $paging_size = intval( foogallery_gallery_template_setting( 'paging_size', 20 ) ); |
| 101 | $paging_scroll = foogallery_gallery_template_setting( 'paging_scroll', 'true' ) === 'true'; |
| 102 | $paging_output = foogallery_gallery_template_setting( 'paging_output', '' ); |
| 103 | |
| 104 | //force bottom position for infinite and loadMore paging |
| 105 | if ( 'infinite' === $paging || 'loadMore' === $paging ) { |
| 106 | $paging_position = 'bottom'; |
| 107 | } |
| 108 | |
| 109 | $paging_options = array( |
| 110 | 'type' => $paging, |
| 111 | 'size' => $paging_size, |
| 112 | 'position' => $paging_position, |
| 113 | 'scrollToTop' => $paging_scroll, |
| 114 | 'output' => $paging_output |
| 115 | ); |
| 116 | |
| 117 | if ( !empty( $paging_theme ) ) { |
| 118 | $paging_options['theme'] = $paging_theme; |
| 119 | } |
| 120 | |
| 121 | if ( 'pagination' === $paging ) { |
| 122 | $paging_options['limit'] = intval( foogallery_gallery_template_setting( 'paging_limit', 5 ) ); |
| 123 | $paging_options['showFirstLast'] = foogallery_gallery_template_setting( 'paging_showFirstLast', 'true' ) === 'true'; |
| 124 | $paging_options['showPrevNext'] = foogallery_gallery_template_setting( 'paging_showPrevNext', 'true' ) === 'true'; |
| 125 | $paging_options['showPrevNextMore'] = foogallery_gallery_template_setting( 'paging_showPrevNextMore', 'true' ) === 'true'; |
| 126 | } |
| 127 | |
| 128 | //cache the paging options on the gallery to be used later |
| 129 | foogallery_current_gallery_set_cached_value( 'paging', $paging_options ); |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Renders the top pagination placeholder |
| 136 | * |
| 137 | * @param $foogallery FooGallery |
| 138 | */ |
| 139 | function output_pagination_placeholders_before( $foogallery ) { |
| 140 | $this->output_pagination_placeholder( $foogallery, 'top' ); |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Renders the bottom pagination placeholder |
| 145 | * |
| 146 | * @param $foogallery FooGallery |
| 147 | */ |
| 148 | function output_pagination_placeholders_after( $foogallery ) { |
| 149 | $this->output_pagination_placeholder( $foogallery, 'bottom' ); |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * render the pagination placeholder |
| 154 | * |
| 155 | * @param $foogallery FooGallery |
| 156 | * @param $position |
| 157 | */ |
| 158 | function output_pagination_placeholder( $foogallery, $position ) { |
| 159 | if ( foogallery_current_gallery_has_cached_value('paging' ) ) { |
| 160 | $paging_options = foogallery_current_gallery_get_cached_value( 'paging' ); |
| 161 | |
| 162 | //check to see if the page size is less than the number of items |
| 163 | if ( $foogallery->attachment_count() > intval( $paging_options['size'] ) ) { |
| 164 | |
| 165 | $paging_position = $paging_options['position']; |
| 166 | if ( $position === $paging_position || 'both' === $paging_position ) { |
| 167 | |
| 168 | $paging_type = $paging_options['type']; |
| 169 | |
| 170 | $paging_types_that_require_placeholders = apply_filters( 'foogallery_pagination_types_require_placeholders', array( 'dots' ) ); |
| 171 | |
| 172 | if ( in_array( $paging_type, $paging_types_that_require_placeholders ) ) { |
| 173 | $paging_type = apply_filters( 'foogallery_pagination_format_type_for_placeholder', $paging_type ); |
| 174 | |
| 175 | echo '<nav id="' . esc_attr( $foogallery->container_id() ) . '_paging-' . esc_attr( $position ) . '" class="fg-paging-container fg-ph-' . esc_attr( $paging_type ) . '"></nav>'; |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * Add paging fields to the gallery template |
| 184 | * |
| 185 | * @uses "foogallery_override_gallery_template_fields" |
| 186 | * @param $fields |
| 187 | * @param $template |
| 188 | * |
| 189 | * @return array |
| 190 | */ |
| 191 | function add_paging_fields( $fields, $template ) { |
| 192 | $paging_support = false; |
| 193 | if ( $template && is_array( $template ) && array_key_exists( 'paging_support', $template ) ) { |
| 194 | $paging_support = $template['paging_support']; |
| 195 | } |
| 196 | |
| 197 | if ( $paging_support ) { |
| 198 | $fields[] = array( |
| 199 | 'id' => 'paging_type', |
| 200 | 'title' => __( 'Paging Type', 'foogallery' ), |
| 201 | 'desc' => __( 'Add paging to a large gallery.', 'foogallery' ), |
| 202 | 'section_id' => 'paging', |
| 203 | 'type' => 'radio', |
| 204 | 'default' => '', |
| 205 | 'choices' => apply_filters( 'foogallery_gallery_template_paging_type_choices', array( |
| 206 | '' => __( 'None', 'foogallery' ), |
| 207 | 'dots' => __( 'Dots', 'foogallery' ) |
| 208 | ) ), |
| 209 | 'row_data'=> array( |
| 210 | 'data-foogallery-change-selector' => 'input', |
| 211 | 'data-foogallery-preview' => 'shortcode', |
| 212 | 'data-foogallery-value-selector' => 'input:checked', |
| 213 | 'data-foogallery-persist' => true |
| 214 | ) |
| 215 | ); |
| 216 | |
| 217 | $fields[] = array( |
| 218 | 'id' => 'paging_size', |
| 219 | 'title' => __( 'Page Size', 'foogallery' ), |
| 220 | 'desc' => __( 'The size of your pages.', 'foogallery' ), |
| 221 | 'section_id' => 'paging', |
| 222 | 'type' => 'number', |
| 223 | 'class' => 'small-text', |
| 224 | 'default' => 20, |
| 225 | 'step' => '1', |
| 226 | 'min' => '0', |
| 227 | 'mobile' => array( |
| 228 | 'default' => 6, |
| 229 | 'data_option' => array( 'paging', 'size' ), |
| 230 | ), |
| 231 | 'row_data'=> array( |
| 232 | 'data-foogallery-change-selector' => 'input', |
| 233 | 'data-foogallery-preview' => 'shortcode', |
| 234 | 'data-foogallery-hidden' => true, |
| 235 | 'data-foogallery-show-when-field' => 'paging_type', |
| 236 | 'data-foogallery-show-when-field-operator' => 'regex', |
| 237 | 'data-foogallery-show-when-field-value' => 'dots|pagination|infinite|loadMore', |
| 238 | 'data-foogallery-persist' => true |
| 239 | ) |
| 240 | ); |
| 241 | |
| 242 | $fields[] = array( |
| 243 | 'id' => 'paging_position', |
| 244 | 'title' => __( 'Position', 'foogallery' ), |
| 245 | 'desc' => __( 'The position of the paging for either dots or pagination.', 'foogallery' ), |
| 246 | 'section_id' => 'paging', |
| 247 | 'type' => 'radio', |
| 248 | 'default' => 'bottom', |
| 249 | 'choices' => apply_filters( 'foogallery_gallery_template_paging_position_choices', array( |
| 250 | '' => __( 'None', 'foogallery' ), |
| 251 | 'top' => __( 'Top', 'foogallery' ), |
| 252 | 'bottom' => __( 'Bottom', 'foogallery' ), |
| 253 | 'both' => __( 'Both', 'foogallery' ) |
| 254 | ) ), |
| 255 | 'row_data'=> array( |
| 256 | 'data-foogallery-hidden' => true, |
| 257 | 'data-foogallery-show-when-field-operator' => 'regex', |
| 258 | 'data-foogallery-show-when-field' => 'paging_type', |
| 259 | 'data-foogallery-show-when-field-value' => 'dots|pagination', |
| 260 | 'data-foogallery-change-selector' => 'input', |
| 261 | 'data-foogallery-preview' => 'shortcode', |
| 262 | 'data-foogallery-persist' => true |
| 263 | ) |
| 264 | ); |
| 265 | |
| 266 | $fields[] = array( |
| 267 | 'id' => 'paging_theme', |
| 268 | 'title' => __( 'Theme', 'foogallery' ), |
| 269 | 'desc' => __( 'The theme used for pagination. Default uses the theme of the gallery.', 'foogallery' ), |
| 270 | 'section_id' => 'paging', |
| 271 | 'type' => 'radio', |
| 272 | 'default' => '', |
| 273 | 'choices' => apply_filters( 'foogallery_gallery_template_paging_theme_choices', array( |
| 274 | '' => __( 'Default', 'foogallery' ), |
| 275 | 'fg-light' => __( 'Light', 'foogallery' ), |
| 276 | 'fg-dark' => __( 'Dark', 'foogallery' ), |
| 277 | 'fg-custom' => __( 'Custom', 'foogallery' ), |
| 278 | ) ), |
| 279 | 'row_data'=> array( |
| 280 | 'data-foogallery-change-selector' => 'input', |
| 281 | 'data-foogallery-preview' => 'shortcode', |
| 282 | 'data-foogallery-hidden' => true, |
| 283 | 'data-foogallery-show-when-field' => 'paging_type', |
| 284 | 'data-foogallery-show-when-field-operator' => 'regex', |
| 285 | 'data-foogallery-show-when-field-value' => 'dots|pagination|loadMore', |
| 286 | 'data-foogallery-persist' => true |
| 287 | ) |
| 288 | ); |
| 289 | |
| 290 | $fields[] = array( |
| 291 | 'id' => 'paging_scroll', |
| 292 | 'title' => __( 'Scroll To Top', 'foogallery' ), |
| 293 | 'desc' => __( 'Whether or not it should scroll to the top of the gallery when paging is changed.', 'foogallery' ), |
| 294 | 'section_id' => 'paging', |
| 295 | 'type' => 'radio', |
| 296 | 'default' => 'false', |
| 297 | 'choices' => array( |
| 298 | 'true' => __( 'Yes', 'foogallery' ), |
| 299 | 'false' => __( 'No', 'foogallery' ), |
| 300 | ), |
| 301 | 'row_data'=> array( |
| 302 | 'data-foogallery-hidden' => true, |
| 303 | 'data-foogallery-show-when-field-operator' => 'regex', |
| 304 | 'data-foogallery-show-when-field' => 'paging_type', |
| 305 | 'data-foogallery-show-when-field-value' => 'dots|pagination', |
| 306 | 'data-foogallery-change-selector' => 'input', |
| 307 | 'data-foogallery-preview' => 'shortcode', |
| 308 | 'data-foogallery-persist' => true |
| 309 | ) |
| 310 | ); |
| 311 | |
| 312 | $fields[] = array( |
| 313 | 'id' => 'paging_limit', |
| 314 | 'title' => __( 'Paging Limit', 'foogallery' ), |
| 315 | 'desc' => __( 'The maximum number of page links to display for the gallery.', 'foogallery' ), |
| 316 | 'section_id' => 'paging', |
| 317 | 'type' => 'number', |
| 318 | 'class' => 'small-text', |
| 319 | 'default' => 5, |
| 320 | 'step' => '1', |
| 321 | 'min' => '0', |
| 322 | 'mobile' => array( |
| 323 | 'default' => 3, |
| 324 | 'data_option' => array( 'paging', 'limit' ), |
| 325 | ), |
| 326 | 'row_data'=> array( |
| 327 | 'data-foogallery-hidden' => true, |
| 328 | 'data-foogallery-show-when-field-operator' => '===', |
| 329 | 'data-foogallery-show-when-field' => 'paging_type', |
| 330 | 'data-foogallery-show-when-field-value' => 'pagination', |
| 331 | 'data-foogallery-change-selector' => 'input', |
| 332 | 'data-foogallery-preview' => 'shortcode', |
| 333 | 'data-foogallery-persist' => true |
| 334 | ) |
| 335 | ); |
| 336 | |
| 337 | $fields[] = array( |
| 338 | 'id' => 'paging_showFirstLast', |
| 339 | 'title' => __( 'First & Last Buttons', 'foogallery' ), |
| 340 | 'desc' => __( 'Whether or not to show the first & last buttons for numbered pagination.', 'foogallery' ), |
| 341 | 'section_id' => 'paging', |
| 342 | 'type' => 'radio', |
| 343 | 'default' => 'true', |
| 344 | 'choices' => array( |
| 345 | 'true' => __( 'Show', 'foogallery' ), |
| 346 | 'false' => __( 'Hide', 'foogallery' ), |
| 347 | ), |
| 348 | 'mobile' => array( |
| 349 | 'default' => 'false', |
| 350 | 'data_option' => array( 'paging', 'showFirstLast' ), |
| 351 | 'data_option_type' => 'boolean', |
| 352 | ), |
| 353 | 'row_data'=> array( |
| 354 | 'data-foogallery-hidden' => true, |
| 355 | 'data-foogallery-show-when-field-operator' => '===', |
| 356 | 'data-foogallery-show-when-field' => 'paging_type', |
| 357 | 'data-foogallery-show-when-field-value' => 'pagination', |
| 358 | 'data-foogallery-change-selector' => 'input', |
| 359 | 'data-foogallery-preview' => 'shortcode', |
| 360 | 'data-foogallery-persist' => true |
| 361 | ) |
| 362 | ); |
| 363 | |
| 364 | $fields[] = array( |
| 365 | 'id' => 'paging_showPrevNext', |
| 366 | 'title' => __( 'Prev & Next Buttons', 'foogallery' ), |
| 367 | 'desc' => __( 'Whether or not to show the previous & next buttons for numbered pagination.', 'foogallery' ), |
| 368 | 'section_id' => 'paging', |
| 369 | 'type' => 'radio', |
| 370 | 'default' => 'true', |
| 371 | 'choices' => array( |
| 372 | 'true' => __( 'Show', 'foogallery' ), |
| 373 | 'false' => __( 'Hide', 'foogallery' ), |
| 374 | ), |
| 375 | 'row_data'=> array( |
| 376 | 'data-foogallery-hidden' => true, |
| 377 | 'data-foogallery-show-when-field-operator' => '===', |
| 378 | 'data-foogallery-show-when-field' => 'paging_type', |
| 379 | 'data-foogallery-show-when-field-value' => 'pagination', |
| 380 | 'data-foogallery-change-selector' => 'input', |
| 381 | 'data-foogallery-preview' => 'shortcode', |
| 382 | 'data-foogallery-persist' => true |
| 383 | ) |
| 384 | ); |
| 385 | |
| 386 | $fields[] = array( |
| 387 | 'id' => 'paging_showPrevNextMore', |
| 388 | 'title' => __( 'More Buttons', 'foogallery' ), |
| 389 | 'desc' => __( 'Whether or not to show the previous & next more buttons for numbered pagination.', 'foogallery' ), |
| 390 | 'section_id' => 'paging', |
| 391 | 'type' => 'radio', |
| 392 | 'default' => 'true', |
| 393 | 'choices' => array( |
| 394 | 'true' => __( 'Show', 'foogallery' ), |
| 395 | 'false' => __( 'Hide', 'foogallery' ), |
| 396 | ), |
| 397 | 'mobile' => array( |
| 398 | 'default' => 'false', |
| 399 | 'data_option' => array( 'paging', 'showPrevNextMore' ), |
| 400 | 'data_option_type' => 'boolean', |
| 401 | ), |
| 402 | 'row_data'=> array( |
| 403 | 'data-foogallery-hidden' => true, |
| 404 | 'data-foogallery-show-when-field-operator' => '===', |
| 405 | 'data-foogallery-show-when-field' => 'paging_type', |
| 406 | 'data-foogallery-show-when-field-value' => 'pagination', |
| 407 | 'data-foogallery-change-selector' => 'input', |
| 408 | 'data-foogallery-preview' => 'shortcode', |
| 409 | 'data-foogallery-persist' => true |
| 410 | ) |
| 411 | ); |
| 412 | |
| 413 | $fields[] = array( |
| 414 | 'id' => 'paging_output', |
| 415 | 'title' => __( 'Paging Output', 'foogallery' ), |
| 416 | 'desc' => __( 'How the paging items are output. We recommend that very large galleries output as JSON.', 'foogallery' ), |
| 417 | 'section_id' => 'paging', |
| 418 | 'type' => 'radio', |
| 419 | 'default' => '', |
| 420 | 'choices' => array( |
| 421 | '' => __( 'Fastest (JSON)', 'foogallery' ), |
| 422 | 'html' => __( 'Legacy (HTML)', 'foogallery' ) |
| 423 | ), |
| 424 | 'row_data'=> array( |
| 425 | 'data-foogallery-change-selector' => 'input', |
| 426 | 'data-foogallery-preview' => 'shortcode', |
| 427 | 'data-foogallery-value-selector' => 'input:checked', |
| 428 | 'data-foogallery-hidden' => true, |
| 429 | 'data-foogallery-show-when-field' => 'paging_type', |
| 430 | 'data-foogallery-show-when-field-operator' => '!==', |
| 431 | 'data-foogallery-show-when-field-value' => '', |
| 432 | 'data-foogallery-persist' => true |
| 433 | ) |
| 434 | ); |
| 435 | } |
| 436 | |
| 437 | return $fields; |
| 438 | } |
| 439 | |
| 440 | /** |
| 441 | * Add the required paging data options if needed |
| 442 | * |
| 443 | * @param $attributes array |
| 444 | * @param $gallery FooGallery |
| 445 | * |
| 446 | * @return array |
| 447 | */ |
| 448 | function add_paging_data_options($options, $gallery, $attributes) { |
| 449 | if ( foogallery_current_gallery_has_cached_value('paging' ) ) { |
| 450 | $options['paging'] = foogallery_current_gallery_get_cached_value( 'paging' ); |
| 451 | } |
| 452 | return $options; |
| 453 | } |
| 454 | |
| 455 | /** |
| 456 | * Add the optional mobile page size to the client paging options. |
| 457 | * |
| 458 | * @param array $options Mobile client options. |
| 459 | * @param FooGallery $_gallery Gallery instance (unused). |
| 460 | * @param array $_attributes Gallery container attributes (unused). |
| 461 | * |
| 462 | * @return array |
| 463 | */ |
| 464 | function add_mobile_paging_data_options( $options, $_gallery, $_attributes ) { |
| 465 | $paging = foogallery_current_gallery_get_cached_value( 'paging' ); |
| 466 | if ( ! is_array( $paging ) ) { |
| 467 | return $options; |
| 468 | } |
| 469 | |
| 470 | $page_size = foogallery_gallery_template_mobile_setting( 'mobile_paging_size', null ); |
| 471 | if ( null === $page_size ) { |
| 472 | return $options; |
| 473 | } |
| 474 | if ( ! is_scalar( $page_size ) || ! is_numeric( trim( (string) $page_size ) ) ) { |
| 475 | $page_size = 6; |
| 476 | } |
| 477 | |
| 478 | $options['paging']['size'] = max( 0, intval( $page_size ) ); |
| 479 | |
| 480 | return $options; |
| 481 | } |
| 482 | |
| 483 | /** |
| 484 | * Override the attachments returned for rendering a paginated gallery to the first page only |
| 485 | * The rest of the items will be added to the script block below the gallery as json items |
| 486 | * This is only when paging_output is JSON. When it's HTML then the all items are rendered |
| 487 | * |
| 488 | * @param bool $override |
| 489 | * @param FooGallery $gallery |
| 490 | * @return bool|array |
| 491 | */ |
| 492 | function attachments_override( $override, $gallery ) { |
| 493 | |
| 494 | if ( foogallery_current_gallery_has_cached_value('paging' ) ) { |
| 495 | |
| 496 | $paging_options = foogallery_current_gallery_get_cached_value( 'paging' ); |
| 497 | $page_size = intval( $paging_options['size'] ); |
| 498 | $output = $paging_options['output']; |
| 499 | |
| 500 | if ( $page_size > 0 ) { |
| 501 | $attachments = $gallery->attachments(); |
| 502 | |
| 503 | if ( $output === 'html' ) { |
| 504 | $index = 0; |
| 505 | foreach ( $attachments as &$attachment ) { |
| 506 | $index++; |
| 507 | if ( $index > $page_size ) { |
| 508 | $attachment->class = 'fg-hidden'; |
| 509 | } |
| 510 | } |
| 511 | return $attachments; |
| 512 | |
| 513 | } else { |
| 514 | //return the first page of attachments |
| 515 | return array_splice( $attachments, 0, $page_size ); |
| 516 | } |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | return $override; |
| 521 | } |
| 522 | |
| 523 | /** |
| 524 | * Output a script block with all the gallery attachments as json |
| 525 | * |
| 526 | * @param FooGallery $gallery |
| 527 | */ |
| 528 | function output_paging_script_block( $gallery ) { |
| 529 | if ( foogallery_current_gallery_has_cached_value('paging' ) ) { |
| 530 | $paging_options = foogallery_current_gallery_get_cached_value( 'paging' ); |
| 531 | $page_size = intval( $paging_options['size'] ); |
| 532 | $output = $paging_options['output']; |
| 533 | |
| 534 | if ( $page_size > 0 && $output === '' ) { |
| 535 | //get the attachments that are not on the first page |
| 536 | $attachments = array_slice( $gallery->attachments(), $page_size ); |
| 537 | foogallery_render_script_block_for_json_items( $gallery, $attachments ); |
| 538 | foogallery_render_noscript_block_for_json_items( $gallery, $attachments ); |
| 539 | } |
| 540 | } |
| 541 | } |
| 542 | } |
| 543 | } |
| 544 |