GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
class-gravityview-plugin-hooks-gravity-forms-dropbox.php
Go to the documentation of this file.
1 <?php
2 /**
3  * Add Gravity Forms Dropbox compatibility
4  *
5  * @file class-gravityview-plugin-hooks-gravity-forms-dropbox.php
6  * @package GravityView
7  * @license GPL2+
8  * @author GravityView <[email protected]>
9  * @link https://gravityview.co
10  * @copyright Copyright 2017, Katz Web Services, Inc.
11  *
12  * @since 1.22.3
13  */
14 
15 /**
16  * @since 1.22.3
17  */
19 
20  /**
21  * @var string gf_dropbox() wrapper function only exists in Version 2.x; don't want to support 1.x
22  * @since 1.22.3
23  */
24  protected $function_name = 'gf_dropbox';
25 
26  /**
27  * @since 1.22.3
28  */
29  protected function add_hooks() {
30  parent::add_hooks();
31 
32  add_filter( 'gravityview/fields/fileupload/extension', array( $this, 'filter_file_extension' ) );
33  add_filter( 'gravityview/fields/fileupload/file_path', array( $this, 'filter_file_path' ) );
34  add_filter( 'gravityview/fields/fileupload/image_atts', array( $this, 'filter_image_atts' ) );
35  }
36 
37  /**
38  * When the image file source includes `?raw=1`, don't validate the source, since we know it's Dropbox or similar.
39  *
40  * @since 2.14.3
41  *
42  * @param array{src:string,class:string,alt:string,width:string} $image_atts
43  *
44  * @return array Image attributes array, possibly with `validate_src` disabled.
45  */
46  function filter_image_atts( $image_atts = array() ) {
47 
48  $image_source = rgar( $image_atts, 'src', '' );
49 
50  if ( false === strpos( $image_source, '?raw=1' ) ) {
51  return $image_atts;
52  }
53 
54  // The image source has ?raw=1; don't check for valid image extensions.
55  $image_atts['validate_src'] = false;
56 
57  return $image_atts;
58  }
59 
60  /**
61  * Convert links to view content on Dropbox.com to direct-access files.
62  *
63  * @since 1.22.3
64  *
65  * @param string $string Original string (file path or extension).
66  *
67  * @return string File path or extension, with Dropbox URLs modified.
68  */
69  function filter_file_extension( $string = '' ) {
70 
71  $extension = str_replace( '?dl=0', '', $string );
72 
73  if ( in_array( $extension, GravityView_Image::get_image_extensions(), true ) ) {
74  return $extension;
75  }
76 
77  return $string;
78  }
79 
80  /**
81  * Convert links to view content on Dropbox.com to direct-access files
82  *
83  * @since 1.22.3
84  *
85  * @param string $string Original string (file path or extension)
86  *
87  * @return string File path or extension, with Dropbox URLs modified
88  */
89  function filter_file_path( $string = '' ) {
90  return str_replace( '?dl=0', '?raw=1', $string );
91  }
92 }
93 
filter_file_path( $string='')
Convert links to view content on Dropbox.com to direct-access files.
$image_atts
Definition: post_image.php:92
filter_file_extension( $string='')
Convert links to view content on Dropbox.com to direct-access files.
filter_image_atts( $image_atts=array())
When the image file source includes ?raw=1, don&#39;t validate the source, since we know it&#39;s Dropbox or ...
Abstract class that makes it easy for plugins and themes to register no-conflict scripts and styles...
static get_image_extensions()
Returns an array of file extensions recognized by GravityView as images.