fooplugins /
foogallery
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | if ( !class_exists( 'FooGallery_Image_Viewer_Gallery_Template' ) ) { |
||
| 4 | |||
| 5 | define('FOOGALLERY_IMAGE_VIEWER_GALLERY_TEMPLATE_URL', plugin_dir_url( __FILE__ )); |
||
| 6 | |||
| 7 | class FooGallery_Image_Viewer_Gallery_Template { |
||
|
0 ignored issues
–
show
|
|||
| 8 | /** |
||
| 9 | * Wire up everything we need to run the extension |
||
| 10 | */ |
||
| 11 | function __construct() { |
||
|
0 ignored issues
–
show
|
|||
| 12 | add_filter( 'foogallery_gallery_templates', array( $this, 'add_template' ) ); |
||
| 13 | |||
| 14 | //add extra fields to the templates |
||
| 15 | add_filter( 'foogallery_override_gallery_template_fields-image-viewer', array( $this, 'add_common_thumbnail_fields' ), 10, 2 ); |
||
| 16 | |||
| 17 | add_action( 'foogallery_located_template-image-viewer', array( $this, 'enqueue_dependencies' ) ); |
||
| 18 | |||
| 19 | add_filter( 'foogallery_gallery_templates_files', array( $this, 'register_myself' ) ); |
||
| 20 | |||
| 21 | add_filter( 'foogallery_template_thumbnail_dimensions-image-viewer', array( $this, 'get_thumbnail_dimensions' ), 10, 2 ); |
||
| 22 | |||
| 23 | //override specific settings when saving the gallery |
||
| 24 | add_filter( 'foogallery_save_gallery_settings-image-viewer', array( $this, 'override_settings'), 10, 3 ); |
||
| 25 | |||
| 26 | //build up any preview arguments |
||
| 27 | add_filter( 'foogallery_preview_arguments-image-viewer', array( $this, 'preview_arguments' ), 10, 2 ); |
||
| 28 | |||
| 29 | //build up the thumb dimensions from some arguments |
||
| 30 | add_filter( 'foogallery_calculate_thumbnail_dimensions-image-viewer', array( $this, 'build_thumbnail_dimensions_from_arguments' ), 10, 2 ); |
||
| 31 | |||
| 32 | //alter the crop value if needed |
||
| 33 | add_filter( 'foogallery_render_gallery_template_field_value', array( $this, 'alter_field_value'), 10, 4 ); |
||
| 34 | |||
| 35 | //build up the arguments needed for rendering this template |
||
| 36 | add_filter( 'foogallery_gallery_template_arguments-image-viewer', array( $this, 'build_gallery_template_arguments' ) ); |
||
| 37 | |||
| 38 | //add the data options needed for image viewer |
||
| 39 | add_filter( 'foogallery_build_container_data_options-image-viewer', array( $this, 'add_data_options' ), 10, 3 ); |
||
| 40 | } |
||
| 41 | |||
| 42 | function alter_field_value( $value, $field, $gallery, $template ) { |
||
|
0 ignored issues
–
show
|
|||
| 43 | //only do something if we are dealing with the thumbnail_dimensions field in this template |
||
| 44 | if ( 'image-viewer' === $template['slug'] && 'thumbnail_size' === $field['id'] ) { |
||
| 45 | if ( !array_key_exists( 'crop', $value ) ) { |
||
| 46 | $value['crop'] = true; |
||
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 50 | return $value; |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Register myself so that all associated JS and CSS files can be found and automatically included |
||
| 55 | * @param $extensions |
||
| 56 | * |
||
| 57 | * @return array |
||
| 58 | */ |
||
| 59 | function register_myself( $extensions ) { |
||
|
0 ignored issues
–
show
|
|||
| 60 | $extensions[] = __FILE__; |
||
| 61 | return $extensions; |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Add our gallery template to the list of templates available for every gallery |
||
| 66 | * @param $gallery_templates |
||
| 67 | * |
||
| 68 | * @return array |
||
| 69 | */ |
||
| 70 | function add_template( $gallery_templates ) { |
||
|
0 ignored issues
–
show
|
|||
| 71 | |||
| 72 | $gallery_templates[] = array( |
||
| 73 | 'slug' => 'image-viewer', |
||
| 74 | 'name' => __( 'Image Viewer', 'foogallery' ), |
||
| 75 | 'preview_support' => true, |
||
| 76 | 'common_fields_support' => true, |
||
| 77 | 'lazyload_support' => true, |
||
| 78 | 'mandatory_classes' => 'fg-image-viewer', |
||
| 79 | 'thumbnail_dimensions' => true, |
||
| 80 | 'fields' => array( |
||
| 81 | array( |
||
| 82 | 'id' => 'thumbnail-help', |
||
| 83 | 'title' => __( 'Thumbnail Help', 'foogallery' ), |
||
| 84 | 'desc' => __( 'It is recommended to crop your thumbnails, so that your gallery remains a constant size. If you do not crop, then the size of the gallery could potentially change for each thumbnail.', 'foogallery' ), |
||
| 85 | 'section' => __( 'General', 'foogallery' ), |
||
| 86 | 'type' => 'help' |
||
| 87 | ), |
||
| 88 | array( |
||
| 89 | 'id' => 'thumbnail_size', |
||
| 90 | 'title' => __( 'Thumb Size', 'foogallery' ), |
||
| 91 | 'section' => __( 'General', 'foogallery' ), |
||
| 92 | 'desc' => __( 'Choose the size of your thumbnails', 'foogallery' ), |
||
| 93 | 'type' => 'thumb_size', |
||
| 94 | 'default' => array( |
||
| 95 | 'width' => 640, |
||
| 96 | 'height' => 360, |
||
| 97 | 'crop' => true |
||
| 98 | ), |
||
| 99 | 'row_data'=> array( |
||
| 100 | 'data-foogallery-change-selector' => 'input', |
||
| 101 | 'data-foogallery-preview' => 'shortcode' |
||
| 102 | ) |
||
| 103 | ), |
||
| 104 | array( |
||
| 105 | 'id' => 'thumbnail_link', |
||
| 106 | 'title' => __( 'Thumb Link', 'foogallery' ), |
||
| 107 | 'section' => __( 'General', 'foogallery' ), |
||
| 108 | 'default' => 'image' , |
||
| 109 | 'type' => 'thumb_link', |
||
| 110 | 'desc' => __( 'You can choose to either link each thumbnail to the full size image or to the image\'s attachment page', 'foogallery') |
||
| 111 | ), |
||
| 112 | array( |
||
| 113 | 'id' => 'lightbox', |
||
| 114 | 'title' => __( 'Lightbox', 'foogallery' ), |
||
| 115 | 'section' => __( 'General', 'foogallery' ), |
||
| 116 | 'desc' => __( 'Choose which lightbox you want to use in the gallery', 'foogallery' ), |
||
| 117 | 'default' => 'none', |
||
| 118 | 'type' => 'lightbox' |
||
| 119 | ), |
||
| 120 | array( |
||
| 121 | 'id' => 'alignment', |
||
| 122 | 'title' => __( 'Alignment', 'foogallery' ), |
||
| 123 | 'section' => __( 'General', 'foogallery' ), |
||
| 124 | 'desc' => __( 'The horizontal alignment of the thumbnails inside the gallery', 'foogallery' ), |
||
| 125 | 'default' => 'fg-center', |
||
| 126 | 'type' => 'radio', |
||
| 127 | 'spacer' => '<span class="spacer"></span>', |
||
| 128 | 'choices' => array( |
||
| 129 | 'fg-left' => __( 'Left', 'foogallery' ), |
||
| 130 | 'fg-center' => __( 'Center', 'foogallery' ), |
||
| 131 | 'fg-right' => __( 'Right', 'foogallery' ), |
||
| 132 | ), |
||
| 133 | 'row_data'=> array( |
||
| 134 | 'data-foogallery-change-selector' => 'input:radio', |
||
| 135 | 'data-foogallery-preview' => 'class' |
||
| 136 | ) |
||
| 137 | ), |
||
| 138 | array( |
||
| 139 | 'id' => 'looping', |
||
| 140 | 'title' => __( 'Loop Images', 'foogallery' ), |
||
| 141 | 'section' => __( 'General', 'foogallery' ), |
||
| 142 | 'desc' => __( 'When navigating through the images, do you want to loop image back to the first after you navigate past the last image?', 'foogallery' ), |
||
| 143 | 'default' => 'enabled', |
||
| 144 | 'type' => 'radio', |
||
| 145 | 'spacer' => '<span class="spacer"></span>', |
||
| 146 | 'choices' => array( |
||
| 147 | 'disabled' => __( 'Disabled', 'foogallery' ), |
||
| 148 | 'enabled' => __( 'Looping Enabled', 'foogallery' ), |
||
| 149 | ), |
||
| 150 | 'row_data'=> array( |
||
| 151 | 'data-foogallery-change-selector' => 'input:radio', |
||
| 152 | 'data-foogallery-preview' => 'shortcode' |
||
| 153 | ) |
||
| 154 | ), |
||
| 155 | array( |
||
| 156 | 'id' => 'language-help', |
||
| 157 | 'title' => __( 'Language Help', 'foogallery' ), |
||
| 158 | 'desc' => __( 'This gallery template shows the below items of text. Change them to suit your preference or language.', 'foogallery' ), |
||
| 159 | 'section' => __( 'General', 'foogallery' ), |
||
| 160 | 'type' => 'help' |
||
| 161 | ), |
||
| 162 | array( |
||
| 163 | 'id' => 'text-prev', |
||
| 164 | 'title' => __( '"Prev" Text', 'foogallery' ), |
||
| 165 | 'section' => __( 'General', 'foogallery' ), |
||
| 166 | 'type' => 'text', |
||
| 167 | 'default' => __('Prev', 'foogallery'), |
||
| 168 | 'row_data'=> array( |
||
| 169 | 'data-foogallery-change-selector' => 'input', |
||
| 170 | 'data-foogallery-preview' => 'shortcode' |
||
| 171 | ) |
||
| 172 | ), |
||
| 173 | array( |
||
| 174 | 'id' => 'text-of', |
||
| 175 | 'title' => __( '"of" Text', 'foogallery' ), |
||
| 176 | 'section' => __( 'General', 'foogallery' ), |
||
| 177 | 'type' => 'text', |
||
| 178 | 'default' => __('of', 'foogallery'), |
||
| 179 | 'row_data'=> array( |
||
| 180 | 'data-foogallery-change-selector' => 'input', |
||
| 181 | 'data-foogallery-preview' => 'shortcode' |
||
| 182 | ) |
||
| 183 | ), |
||
| 184 | array( |
||
| 185 | 'id' => 'text-next', |
||
| 186 | 'title' => __( '"Next" Text', 'foogallery' ), |
||
| 187 | 'section' => __( 'General', 'foogallery' ), |
||
| 188 | 'type' => 'text', |
||
| 189 | 'default' => __('Next', 'foogallery'), |
||
| 190 | 'row_data'=> array( |
||
| 191 | 'data-foogallery-change-selector' => 'input', |
||
| 192 | 'data-foogallery-preview' => 'shortcode' |
||
| 193 | ) |
||
| 194 | ) |
||
| 195 | ) |
||
| 196 | ); |
||
| 197 | |||
| 198 | return $gallery_templates; |
||
| 199 | } |
||
| 200 | |||
| 201 | /** |
||
| 202 | * Add thumbnail fields to the gallery template |
||
| 203 | * |
||
| 204 | * @uses "foogallery_override_gallery_template_fields" |
||
| 205 | * @param $fields |
||
| 206 | * @param $template |
||
| 207 | * |
||
| 208 | * @return array |
||
| 209 | */ |
||
| 210 | function add_common_thumbnail_fields( $fields, $template ) { |
||
|
0 ignored issues
–
show
|
|||
| 211 | |||
| 212 | //update specific fields |
||
| 213 | foreach ($fields as &$field) { |
||
| 214 | if ( 'rounded_corners' === $field['id'] ) { |
||
| 215 | unset( $field['choices']['fg-round-full'] ); |
||
| 216 | } |
||
| 217 | } |
||
| 218 | |||
| 219 | return $fields; |
||
| 220 | } |
||
| 221 | |||
| 222 | /** |
||
| 223 | * Enqueue scripts that the default gallery template relies on |
||
| 224 | */ |
||
| 225 | function enqueue_dependencies( $gallery ) { |
||
|
0 ignored issues
–
show
|
|||
| 226 | //enqueue core files |
||
| 227 | foogallery_enqueue_core_gallery_template_style(); |
||
| 228 | foogallery_enqueue_core_gallery_template_script(); |
||
| 229 | } |
||
| 230 | |||
| 231 | /** |
||
| 232 | * Get the thumb dimensions arguments saved for the gallery for this gallery template |
||
| 233 | * |
||
| 234 | * @param array $dimensions |
||
| 235 | * @param FooGallery $foogallery |
||
| 236 | * |
||
| 237 | * @return mixed |
||
| 238 | */ |
||
| 239 | function get_thumbnail_dimensions( $dimensions, $foogallery ) { |
||
|
0 ignored issues
–
show
|
|||
| 240 | $dimensions = $foogallery->get_meta( 'image-viewer_thumbnail_size', array( |
||
| 241 | 'width' => 640, |
||
| 242 | 'height' => 360, |
||
| 243 | 'crop' => true |
||
| 244 | ) ); |
||
| 245 | if ( !array_key_exists( 'crop', $dimensions ) ) { |
||
| 246 | $dimensions['crop'] = true; |
||
| 247 | } |
||
| 248 | return $dimensions; |
||
| 249 | } |
||
| 250 | |||
| 251 | /** |
||
| 252 | * Override specific settings so that the gallery template will always work |
||
| 253 | * |
||
| 254 | * @param $settings |
||
| 255 | * @param $post_id |
||
| 256 | * @param $form_data |
||
| 257 | * |
||
| 258 | * @return mixed |
||
| 259 | */ |
||
| 260 | function override_settings($settings, $post_id, $form_data) { |
||
|
0 ignored issues
–
show
|
|||
| 261 | if ( 'fg-round-full' === $settings['image-viewer_rounded_corners'] ) { |
||
| 262 | $settings['image-viewer_rounded_corners'] = 'fg-round-large'; |
||
| 263 | } |
||
| 264 | |||
| 265 | return $settings; |
||
| 266 | } |
||
| 267 | |||
| 268 | /** |
||
| 269 | * Build up a arguments used in the preview of the gallery |
||
| 270 | * @param $args |
||
| 271 | * @param $post_data |
||
| 272 | * |
||
| 273 | * @return mixed |
||
| 274 | */ |
||
| 275 | function preview_arguments( $args, $post_data ) { |
||
|
0 ignored issues
–
show
|
|||
| 276 | $args['thumbnail_size'] = $post_data[FOOGALLERY_META_SETTINGS]['image-viewer_thumbnail_size']; |
||
| 277 | $args['text-prev'] = $post_data[FOOGALLERY_META_SETTINGS]['image-viewer_text-prev']; |
||
| 278 | $args['text-of'] = $post_data[FOOGALLERY_META_SETTINGS]['image-viewer_text-of']; |
||
| 279 | $args['text-next'] = $post_data[FOOGALLERY_META_SETTINGS]['image-viewer_text-next']; |
||
| 280 | $args['looping'] = $post_data[FOOGALLERY_META_SETTINGS]['image-viewer_looping']; |
||
| 281 | return $args; |
||
| 282 | } |
||
| 283 | |||
| 284 | /** |
||
| 285 | * Builds thumb dimensions from arguments |
||
| 286 | * |
||
| 287 | * @param array $dimensions |
||
| 288 | * @param array $arguments |
||
| 289 | * |
||
| 290 | * @return mixed |
||
| 291 | */ |
||
| 292 | function build_thumbnail_dimensions_from_arguments( $dimensions, $arguments ) { |
||
|
0 ignored issues
–
show
|
|||
| 293 | if ( array_key_exists( 'thumbnail_size', $arguments) ) { |
||
| 294 | return array( |
||
| 295 | 'height' => intval($arguments['thumbnail_size']['height']), |
||
| 296 | 'width' => intval($arguments['thumbnail_size']['width']), |
||
| 297 | 'crop' => $arguments['thumbnail_size']['crop'] |
||
| 298 | ); |
||
| 299 | } |
||
| 300 | return null; |
||
| 301 | } |
||
| 302 | |||
| 303 | /** |
||
| 304 | * Build up the arguments needed for rendering this gallery template |
||
| 305 | * |
||
| 306 | * @param $args |
||
| 307 | * @return array |
||
| 308 | */ |
||
| 309 | function build_gallery_template_arguments( $args ) { |
||
|
0 ignored issues
–
show
|
|||
| 310 | $args = foogallery_gallery_template_setting( 'thumbnail_size', 'thumbnail' ); |
||
| 311 | if ( !array_key_exists( 'crop', $args ) ) { |
||
| 312 | $args['crop'] = '1'; //we now force thumbs to be cropped by default |
||
| 313 | } |
||
| 314 | $args['link'] = foogallery_gallery_template_setting( 'thumbnail_link', 'image' ); |
||
| 315 | |||
| 316 | return $args; |
||
| 317 | } |
||
| 318 | |||
| 319 | /** |
||
| 320 | * Add the required options |
||
| 321 | * |
||
| 322 | * @param $options |
||
| 323 | * @param $gallery FooGallery |
||
| 324 | * |
||
| 325 | * @param $attributes array |
||
| 326 | * |
||
| 327 | * @return array |
||
| 328 | */ |
||
| 329 | function add_data_options($options, $gallery, $attributes) { |
||
|
0 ignored issues
–
show
|
|||
| 330 | |||
| 331 | $looping = foogallery_gallery_template_setting( 'looping', 'enabled' ) === 'enabled'; |
||
| 332 | $options['template']['loop'] = $looping; |
||
| 333 | |||
| 334 | return $options; |
||
| 335 | } |
||
| 336 | } |
||
| 337 | } |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.