Completed
Push — develop ( 4a998f...09e5ca )
by Zack
10:50
created

GravityView_Plugin_Hooks_Gravity_Forms_Dropbox   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 36
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add_hooks() 0 5 1
A filter_file_path() 0 7 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 18 and the first side effect is on line 55.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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    Katz Web Services, Inc.
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
 */
18
class GravityView_Plugin_Hooks_Gravity_Forms_Dropbox extends GravityView_Plugin_and_Theme_Hooks {
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/file_path', array( $this, 'filter_file_path' ), 10, 3 );
33
	}
34
35
	/**
36
	 * Convert links to view content on Dropbox.com to direct-access files
37
	 *
38
	 * @since 1.22.3
39
	 *
40
	 * @param string $file_path
41
	 * @param array $file_path_info
42
	 * @param array $field_settings
43
	 *
44
	 * @return string File path, with Dropbox URLs modified
45
	 */
46
	function filter_file_path( $file_path = '', $file_path_info = array(), $field_settings = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $file_path_info is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $field_settings is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
47
48
		$file_path = str_replace('www.dropbox.com', 'dl.dropboxusercontent.com', $file_path );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
49
		$file_path = str_replace( '?dl=0', '', $file_path );
50
51
		return $file_path;
52
	}
53
}
54
55
new GravityView_Plugin_Hooks_Gravity_Forms_Dropbox;