Completed
Pull Request — develop (#1713)
by Zack
17:42
created
future/includes/class-gv-collection-widget.php 3 patches
Indentation   +166 added lines, -166 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 
5 5
 /** If this file is called directly, abort. */
6 6
 if (!defined('GRAVITYVIEW_DIR')) {
7
-    exit();
7
+	exit();
8 8
 }
9 9
 
10 10
 /**
@@ -12,169 +12,169 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class Widget_Collection extends Collection
14 14
 {
15
-    /**
16
-     * Add a \GV\Widet to this collection.
17
-     *
18
-     * @param \GV\Widget $widget The widget to add to the internal array.
19
-     *
20
-     * @api
21
-     *
22
-     * @since 2.0
23
-     *
24
-     * @return void
25
-     */
26
-    public function add($widget)
27
-    {
28
-        if (!$widget instanceof Widget) {
29
-            gravityview()->log->error('Widget_Collections can only contain objects of type \GV\Widget.');
30
-
31
-            return;
32
-        }
33
-        parent::add($widget);
34
-    }
35
-
36
-    /**
37
-     * Get a \GV\Widget from this list by UID.
38
-     *
39
-     * @param int $widget_uid The UID of the widget in the collection to get.
40
-     *
41
-     * @api
42
-     *
43
-     * @since 2.0
44
-     *
45
-     * @return \GV\Widget|null The \GV\Widget with the $widget_uid as the UID, or null if not found.
46
-     */
47
-    public function get($widget_uid)
48
-    {
49
-        foreach ($this->all() as $widget) {
50
-            if ($widget->UID == $widget_uid) {
51
-                return $widget;
52
-            }
53
-        }
54
-
55
-        return null;
56
-    }
57
-
58
-    /**
59
-     * Get a copy of this \GV\Widget_Collection filtered by position.
60
-     *
61
-     * @param string $position The position to get the widgets for.
62
-     *                         Can be a wildcard *
63
-     *
64
-     * @api
65
-     *
66
-     * @since
67
-     *
68
-     * @return \GV\Widget_Collection A filtered collection of \GV\Widget, filtered by position.
69
-     */
70
-    public function by_position($position)
71
-    {
72
-        $widgets = new self();
73
-
74
-        $search = implode('.*', array_map('preg_quote', explode('*', $position)));
75
-
76
-        foreach ($this->all() as $widget) {
77
-            if (preg_match("#^{$search}$#", $widget->position)) {
78
-                $widgets->add($widget);
79
-            }
80
-        }
81
-
82
-        return $widgets;
83
-    }
84
-
85
-    /**
86
-     * Get a copy of this \GV\Widget_Collection filtered by ID.
87
-     *
88
-     * @param string $id The IDs to get the widgets for.
89
-     *
90
-     * @api
91
-     *
92
-     * @since
93
-     *
94
-     * @return \GV\Widget_Collection A filtered collection of \GV\Widget, filtered by ID.
95
-     */
96
-    public function by_id($id)
97
-    {
98
-        $widgets = new self();
99
-
100
-        foreach ($this->all() as $widget) {
101
-            if ($id == $widget->get_widget_id()) {
102
-                $widgets->add($widget);
103
-            }
104
-        }
105
-
106
-        return $widgets;
107
-    }
108
-
109
-    /**
110
-     * Parse a configuration array into a Widget_Collection.
111
-     *
112
-     * @param array $configuration The configuration, structured like so:
113
-     *
114
-     * array(
115
-     *
116
-     * 	[other zones]
117
-     *
118
-     * 	'footer_right' => array(
119
-     *
120
-     *   	[other widgets]
121
-     *
122
-     *  	'5372653f25d44' => array(
123
-     *
124
-     *			@see \GV\Widget::as_configuration() for structure
125
-     *  	)
126
-     *
127
-     * 		[other widgets]
128
-     *  )
129
-     *
130
-     * 	[other zones]
131
-     * )
132
-     *
133
-     * @return \GV\Widget_Collection A collection of widgets.
134
-     */
135
-    public static function from_configuration($configuration)
136
-    {
137
-        $widgets = new self();
138
-        foreach ($configuration as $position => $_widgets) {
139
-            if (empty($_widgets) || !is_array($_widgets)) {
140
-                continue;
141
-            }
142
-
143
-            foreach ($_widgets as $uid => $_configuration) {
144
-                if (!$widget = Widget::from_configuration($_configuration)) {
145
-                    continue;
146
-                }
147
-
148
-                $widget->UID = $uid;
149
-                $widget->position = $position;
150
-
151
-                $widgets->add($widget);
152
-            }
153
-        }
154
-
155
-        return $widgets;
156
-    }
157
-
158
-    /**
159
-     * Return a configuration array for this widget collection.
160
-     *
161
-     * @return array See \GV\Widget_Collection::from_configuration() for structure.
162
-     */
163
-    public function as_configuration()
164
-    {
165
-        $configuration = [];
166
-
167
-        /**
168
-         * @var \GV\Widget $widget
169
-         */
170
-        foreach ($this->all() as $widget) {
171
-            if (empty($configuration[$widget->position])) {
172
-                $configuration[$widget->position] = [];
173
-            }
174
-
175
-            $configuration[$widget->position][$widget->UID] = $widget->as_configuration();
176
-        }
177
-
178
-        return $configuration;
179
-    }
15
+	/**
16
+	 * Add a \GV\Widet to this collection.
17
+	 *
18
+	 * @param \GV\Widget $widget The widget to add to the internal array.
19
+	 *
20
+	 * @api
21
+	 *
22
+	 * @since 2.0
23
+	 *
24
+	 * @return void
25
+	 */
26
+	public function add($widget)
27
+	{
28
+		if (!$widget instanceof Widget) {
29
+			gravityview()->log->error('Widget_Collections can only contain objects of type \GV\Widget.');
30
+
31
+			return;
32
+		}
33
+		parent::add($widget);
34
+	}
35
+
36
+	/**
37
+	 * Get a \GV\Widget from this list by UID.
38
+	 *
39
+	 * @param int $widget_uid The UID of the widget in the collection to get.
40
+	 *
41
+	 * @api
42
+	 *
43
+	 * @since 2.0
44
+	 *
45
+	 * @return \GV\Widget|null The \GV\Widget with the $widget_uid as the UID, or null if not found.
46
+	 */
47
+	public function get($widget_uid)
48
+	{
49
+		foreach ($this->all() as $widget) {
50
+			if ($widget->UID == $widget_uid) {
51
+				return $widget;
52
+			}
53
+		}
54
+
55
+		return null;
56
+	}
57
+
58
+	/**
59
+	 * Get a copy of this \GV\Widget_Collection filtered by position.
60
+	 *
61
+	 * @param string $position The position to get the widgets for.
62
+	 *                         Can be a wildcard *
63
+	 *
64
+	 * @api
65
+	 *
66
+	 * @since
67
+	 *
68
+	 * @return \GV\Widget_Collection A filtered collection of \GV\Widget, filtered by position.
69
+	 */
70
+	public function by_position($position)
71
+	{
72
+		$widgets = new self();
73
+
74
+		$search = implode('.*', array_map('preg_quote', explode('*', $position)));
75
+
76
+		foreach ($this->all() as $widget) {
77
+			if (preg_match("#^{$search}$#", $widget->position)) {
78
+				$widgets->add($widget);
79
+			}
80
+		}
81
+
82
+		return $widgets;
83
+	}
84
+
85
+	/**
86
+	 * Get a copy of this \GV\Widget_Collection filtered by ID.
87
+	 *
88
+	 * @param string $id The IDs to get the widgets for.
89
+	 *
90
+	 * @api
91
+	 *
92
+	 * @since
93
+	 *
94
+	 * @return \GV\Widget_Collection A filtered collection of \GV\Widget, filtered by ID.
95
+	 */
96
+	public function by_id($id)
97
+	{
98
+		$widgets = new self();
99
+
100
+		foreach ($this->all() as $widget) {
101
+			if ($id == $widget->get_widget_id()) {
102
+				$widgets->add($widget);
103
+			}
104
+		}
105
+
106
+		return $widgets;
107
+	}
108
+
109
+	/**
110
+	 * Parse a configuration array into a Widget_Collection.
111
+	 *
112
+	 * @param array $configuration The configuration, structured like so:
113
+	 *
114
+	 * array(
115
+	 *
116
+	 * 	[other zones]
117
+	 *
118
+	 * 	'footer_right' => array(
119
+	 *
120
+	 *   	[other widgets]
121
+	 *
122
+	 *  	'5372653f25d44' => array(
123
+	 *
124
+	 *			@see \GV\Widget::as_configuration() for structure
125
+	 *  	)
126
+	 *
127
+	 * 		[other widgets]
128
+	 *  )
129
+	 *
130
+	 * 	[other zones]
131
+	 * )
132
+	 *
133
+	 * @return \GV\Widget_Collection A collection of widgets.
134
+	 */
135
+	public static function from_configuration($configuration)
136
+	{
137
+		$widgets = new self();
138
+		foreach ($configuration as $position => $_widgets) {
139
+			if (empty($_widgets) || !is_array($_widgets)) {
140
+				continue;
141
+			}
142
+
143
+			foreach ($_widgets as $uid => $_configuration) {
144
+				if (!$widget = Widget::from_configuration($_configuration)) {
145
+					continue;
146
+				}
147
+
148
+				$widget->UID = $uid;
149
+				$widget->position = $position;
150
+
151
+				$widgets->add($widget);
152
+			}
153
+		}
154
+
155
+		return $widgets;
156
+	}
157
+
158
+	/**
159
+	 * Return a configuration array for this widget collection.
160
+	 *
161
+	 * @return array See \GV\Widget_Collection::from_configuration() for structure.
162
+	 */
163
+	public function as_configuration()
164
+	{
165
+		$configuration = [];
166
+
167
+		/**
168
+		 * @var \GV\Widget $widget
169
+		 */
170
+		foreach ($this->all() as $widget) {
171
+			if (empty($configuration[$widget->position])) {
172
+				$configuration[$widget->position] = [];
173
+			}
174
+
175
+			$configuration[$widget->position][$widget->UID] = $widget->as_configuration();
176
+		}
177
+
178
+		return $configuration;
179
+	}
180 180
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 namespace GV;
4 4
 
5 5
 /** If this file is called directly, abort. */
6
-if (!defined('GRAVITYVIEW_DIR')) {
6
+if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
7 7
     exit();
8 8
 }
9 9
 
@@ -23,14 +23,14 @@  discard block
 block discarded – undo
23 23
      *
24 24
      * @return void
25 25
      */
26
-    public function add($widget)
26
+    public function add( $widget )
27 27
     {
28
-        if (!$widget instanceof Widget) {
29
-            gravityview()->log->error('Widget_Collections can only contain objects of type \GV\Widget.');
28
+        if ( ! $widget instanceof Widget ) {
29
+            gravityview()->log->error( 'Widget_Collections can only contain objects of type \GV\Widget.' );
30 30
 
31 31
             return;
32 32
         }
33
-        parent::add($widget);
33
+        parent::add( $widget );
34 34
     }
35 35
 
36 36
     /**
@@ -44,10 +44,10 @@  discard block
 block discarded – undo
44 44
      *
45 45
      * @return \GV\Widget|null The \GV\Widget with the $widget_uid as the UID, or null if not found.
46 46
      */
47
-    public function get($widget_uid)
47
+    public function get( $widget_uid )
48 48
     {
49
-        foreach ($this->all() as $widget) {
50
-            if ($widget->UID == $widget_uid) {
49
+        foreach ( $this->all() as $widget ) {
50
+            if ( $widget->UID == $widget_uid ) {
51 51
                 return $widget;
52 52
             }
53 53
         }
@@ -67,15 +67,15 @@  discard block
 block discarded – undo
67 67
      *
68 68
      * @return \GV\Widget_Collection A filtered collection of \GV\Widget, filtered by position.
69 69
      */
70
-    public function by_position($position)
70
+    public function by_position( $position )
71 71
     {
72 72
         $widgets = new self();
73 73
 
74
-        $search = implode('.*', array_map('preg_quote', explode('*', $position)));
74
+        $search = implode( '.*', array_map( 'preg_quote', explode( '*', $position ) ) );
75 75
 
76
-        foreach ($this->all() as $widget) {
77
-            if (preg_match("#^{$search}$#", $widget->position)) {
78
-                $widgets->add($widget);
76
+        foreach ( $this->all() as $widget ) {
77
+            if ( preg_match( "#^{$search}$#", $widget->position ) ) {
78
+                $widgets->add( $widget );
79 79
             }
80 80
         }
81 81
 
@@ -93,13 +93,13 @@  discard block
 block discarded – undo
93 93
      *
94 94
      * @return \GV\Widget_Collection A filtered collection of \GV\Widget, filtered by ID.
95 95
      */
96
-    public function by_id($id)
96
+    public function by_id( $id )
97 97
     {
98 98
         $widgets = new self();
99 99
 
100
-        foreach ($this->all() as $widget) {
101
-            if ($id == $widget->get_widget_id()) {
102
-                $widgets->add($widget);
100
+        foreach ( $this->all() as $widget ) {
101
+            if ( $id == $widget->get_widget_id() ) {
102
+                $widgets->add( $widget );
103 103
             }
104 104
         }
105 105
 
@@ -132,23 +132,23 @@  discard block
 block discarded – undo
132 132
      *
133 133
      * @return \GV\Widget_Collection A collection of widgets.
134 134
      */
135
-    public static function from_configuration($configuration)
135
+    public static function from_configuration( $configuration )
136 136
     {
137 137
         $widgets = new self();
138
-        foreach ($configuration as $position => $_widgets) {
139
-            if (empty($_widgets) || !is_array($_widgets)) {
138
+        foreach ( $configuration as $position => $_widgets ) {
139
+            if ( empty( $_widgets ) || ! is_array( $_widgets ) ) {
140 140
                 continue;
141 141
             }
142 142
 
143
-            foreach ($_widgets as $uid => $_configuration) {
144
-                if (!$widget = Widget::from_configuration($_configuration)) {
143
+            foreach ( $_widgets as $uid => $_configuration ) {
144
+                if ( ! $widget = Widget::from_configuration( $_configuration ) ) {
145 145
                     continue;
146 146
                 }
147 147
 
148 148
                 $widget->UID = $uid;
149 149
                 $widget->position = $position;
150 150
 
151
-                $widgets->add($widget);
151
+                $widgets->add( $widget );
152 152
             }
153 153
         }
154 154
 
@@ -162,17 +162,17 @@  discard block
 block discarded – undo
162 162
      */
163 163
     public function as_configuration()
164 164
     {
165
-        $configuration = [];
165
+        $configuration = [ ];
166 166
 
167 167
         /**
168 168
          * @var \GV\Widget $widget
169 169
          */
170
-        foreach ($this->all() as $widget) {
171
-            if (empty($configuration[$widget->position])) {
172
-                $configuration[$widget->position] = [];
170
+        foreach ( $this->all() as $widget ) {
171
+            if ( empty( $configuration[ $widget->position ] ) ) {
172
+                $configuration[ $widget->position ] = [ ];
173 173
             }
174 174
 
175
-            $configuration[$widget->position][$widget->UID] = $widget->as_configuration();
175
+            $configuration[ $widget->position ][ $widget->UID ] = $widget->as_configuration();
176 176
         }
177 177
 
178 178
         return $configuration;
Please login to merge, or discard this patch.
Braces   +7 added lines, -14 removed lines patch added patch discarded remove patch
@@ -10,8 +10,7 @@  discard block
 block discarded – undo
10 10
 /**
11 11
  * A collection of \GV\Widget objects.
12 12
  */
13
-class Widget_Collection extends Collection
14
-{
13
+class Widget_Collection extends Collection {
15 14
     /**
16 15
      * Add a \GV\Widet to this collection.
17 16
      *
@@ -23,8 +22,7 @@  discard block
 block discarded – undo
23 22
      *
24 23
      * @return void
25 24
      */
26
-    public function add($widget)
27
-    {
25
+    public function add($widget) {
28 26
         if (!$widget instanceof Widget) {
29 27
             gravityview()->log->error('Widget_Collections can only contain objects of type \GV\Widget.');
30 28
 
@@ -44,8 +42,7 @@  discard block
 block discarded – undo
44 42
      *
45 43
      * @return \GV\Widget|null The \GV\Widget with the $widget_uid as the UID, or null if not found.
46 44
      */
47
-    public function get($widget_uid)
48
-    {
45
+    public function get($widget_uid) {
49 46
         foreach ($this->all() as $widget) {
50 47
             if ($widget->UID == $widget_uid) {
51 48
                 return $widget;
@@ -67,8 +64,7 @@  discard block
 block discarded – undo
67 64
      *
68 65
      * @return \GV\Widget_Collection A filtered collection of \GV\Widget, filtered by position.
69 66
      */
70
-    public function by_position($position)
71
-    {
67
+    public function by_position($position) {
72 68
         $widgets = new self();
73 69
 
74 70
         $search = implode('.*', array_map('preg_quote', explode('*', $position)));
@@ -93,8 +89,7 @@  discard block
 block discarded – undo
93 89
      *
94 90
      * @return \GV\Widget_Collection A filtered collection of \GV\Widget, filtered by ID.
95 91
      */
96
-    public function by_id($id)
97
-    {
92
+    public function by_id($id) {
98 93
         $widgets = new self();
99 94
 
100 95
         foreach ($this->all() as $widget) {
@@ -132,8 +127,7 @@  discard block
 block discarded – undo
132 127
      *
133 128
      * @return \GV\Widget_Collection A collection of widgets.
134 129
      */
135
-    public static function from_configuration($configuration)
136
-    {
130
+    public static function from_configuration($configuration) {
137 131
         $widgets = new self();
138 132
         foreach ($configuration as $position => $_widgets) {
139 133
             if (empty($_widgets) || !is_array($_widgets)) {
@@ -160,8 +154,7 @@  discard block
 block discarded – undo
160 154
      *
161 155
      * @return array See \GV\Widget_Collection::from_configuration() for structure.
162 156
      */
163
-    public function as_configuration()
164
-    {
157
+    public function as_configuration() {
165 158
         $configuration = [];
166 159
 
167 160
         /**
Please login to merge, or discard this patch.
future/includes/class-gv-request-frontend.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@
 block discarded – undo
4 4
 
5 5
 /** If this file is called directly, abort. */
6 6
 if (!defined('GRAVITYVIEW_DIR')) {
7
-    exit();
7
+	exit();
8 8
 }
9 9
 
10 10
 /**
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@
 block discarded – undo
3 3
 namespace GV;
4 4
 
5 5
 /** If this file is called directly, abort. */
6
-if (!defined('GRAVITYVIEW_DIR')) {
6
+if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
7 7
     exit();
8 8
 }
9 9
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -10,6 +10,5 @@
 block discarded – undo
10 10
 /**
11 11
  * The default frontend Request class.
12 12
  */
13
-class Frontend_Request extends Request
14
-{
13
+class Frontend_Request extends Request {
15 14
 }
Please login to merge, or discard this patch.
future/includes/class-gv-logger-wp-action.php 3 patches
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 
5 5
 /** If this file is called directly, abort. */
6 6
 if (!defined('GRAVITYVIEW_DIR')) {
7
-    exit();
7
+	exit();
8 8
 }
9 9
 
10 10
 /**
@@ -14,59 +14,59 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class WP_Action_Logger extends Logger
16 16
 {
17
-    /**
18
-     * Logs with an arbitrary level using `do_action` and our
19
-     *  old action handlers.
20
-     *
21
-     * $context['data'] will be passed to the action.
22
-     *
23
-     * @param mixed  $level   The log level.
24
-     * @param string $message The message to log.
25
-     * @param array  $context The context.
26
-     *
27
-     * @return void
28
-     */
29
-    protected function log($level, $message, $context)
30
-    {
31
-        $php_version = (!empty($GLOBALS['GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE'])) ?
32
-            $GLOBALS['GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE'] : phpversion();
17
+	/**
18
+	 * Logs with an arbitrary level using `do_action` and our
19
+	 *  old action handlers.
20
+	 *
21
+	 * $context['data'] will be passed to the action.
22
+	 *
23
+	 * @param mixed  $level   The log level.
24
+	 * @param string $message The message to log.
25
+	 * @param array  $context The context.
26
+	 *
27
+	 * @return void
28
+	 */
29
+	protected function log($level, $message, $context)
30
+	{
31
+		$php_version = (!empty($GLOBALS['GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE'])) ?
32
+			$GLOBALS['GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE'] : phpversion();
33 33
 
34
-        if (version_compare($php_version, '5.4', '>=')) {
35
-            $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3);
36
-            $location = $this->interpolate('{class}{type}{function}', $backtrace[2]);
37
-            $message = $this->interpolate("[$level, $location] $message", $context);
38
-        } else {
39
-            $message = "[$level] $message";
40
-        }
34
+		if (version_compare($php_version, '5.4', '>=')) {
35
+			$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3);
36
+			$location = $this->interpolate('{class}{type}{function}', $backtrace[2]);
37
+			$message = $this->interpolate("[$level, $location] $message", $context);
38
+		} else {
39
+			$message = "[$level] $message";
40
+		}
41 41
 
42
-        switch ($level) {
43
-            case LogLevel::EMERGENCY:
44
-            case LogLevel::ALERT:
45
-            case LogLevel::CRITICAL:
46
-            case LogLevel::ERROR:
47
-                $action = 'error';
48
-                break;
49
-            case LogLevel::WARNING:
50
-            case LogLevel::NOTICE:
51
-            case LogLevel::INFO:
52
-            case LogLevel::DEBUG:
53
-                $action = 'debug';
54
-                break;
55
-        }
42
+		switch ($level) {
43
+			case LogLevel::EMERGENCY:
44
+			case LogLevel::ALERT:
45
+			case LogLevel::CRITICAL:
46
+			case LogLevel::ERROR:
47
+				$action = 'error';
48
+				break;
49
+			case LogLevel::WARNING:
50
+			case LogLevel::NOTICE:
51
+			case LogLevel::INFO:
52
+			case LogLevel::DEBUG:
53
+				$action = 'debug';
54
+				break;
55
+		}
56 56
 
57
-        if (defined('DOING_GRAVITYVIEW_TESTS')) {
58
-            /** Let's make this testable! */
59
-            do_action(
60
-                sprintf('gravityview_log_%s_test', $action),
61
-                $this->interpolate($message, $context),
62
-                empty($context['data']) ? [] : $context['data']
63
-            );
64
-        }
57
+		if (defined('DOING_GRAVITYVIEW_TESTS')) {
58
+			/** Let's make this testable! */
59
+			do_action(
60
+				sprintf('gravityview_log_%s_test', $action),
61
+				$this->interpolate($message, $context),
62
+				empty($context['data']) ? [] : $context['data']
63
+			);
64
+		}
65 65
 
66
-        do_action(
67
-            sprintf('gravityview_log_%s', $action),
68
-            $this->interpolate($message, $context),
69
-            empty($context['data']) ? [] : $context['data']
70
-        );
71
-    }
66
+		do_action(
67
+			sprintf('gravityview_log_%s', $action),
68
+			$this->interpolate($message, $context),
69
+			empty($context['data']) ? [] : $context['data']
70
+		);
71
+	}
72 72
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 namespace GV;
4 4
 
5 5
 /** If this file is called directly, abort. */
6
-if (!defined('GRAVITYVIEW_DIR')) {
6
+if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
7 7
     exit();
8 8
 }
9 9
 
@@ -26,20 +26,20 @@  discard block
 block discarded – undo
26 26
      *
27 27
      * @return void
28 28
      */
29
-    protected function log($level, $message, $context)
29
+    protected function log( $level, $message, $context )
30 30
     {
31
-        $php_version = (!empty($GLOBALS['GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE'])) ?
32
-            $GLOBALS['GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE'] : phpversion();
31
+        $php_version = ( ! empty( $GLOBALS[ 'GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE' ] ) ) ?
32
+            $GLOBALS[ 'GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE' ] : phpversion();
33 33
 
34
-        if (version_compare($php_version, '5.4', '>=')) {
35
-            $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3);
36
-            $location = $this->interpolate('{class}{type}{function}', $backtrace[2]);
37
-            $message = $this->interpolate("[$level, $location] $message", $context);
34
+        if ( version_compare( $php_version, '5.4', '>=' ) ) {
35
+            $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 3 );
36
+            $location = $this->interpolate( '{class}{type}{function}', $backtrace[ 2 ] );
37
+            $message = $this->interpolate( "[$level, $location] $message", $context );
38 38
         } else {
39 39
             $message = "[$level] $message";
40 40
         }
41 41
 
42
-        switch ($level) {
42
+        switch ( $level ) {
43 43
             case LogLevel::EMERGENCY:
44 44
             case LogLevel::ALERT:
45 45
             case LogLevel::CRITICAL:
@@ -54,19 +54,19 @@  discard block
 block discarded – undo
54 54
                 break;
55 55
         }
56 56
 
57
-        if (defined('DOING_GRAVITYVIEW_TESTS')) {
57
+        if ( defined( 'DOING_GRAVITYVIEW_TESTS' ) ) {
58 58
             /** Let's make this testable! */
59 59
             do_action(
60
-                sprintf('gravityview_log_%s_test', $action),
61
-                $this->interpolate($message, $context),
62
-                empty($context['data']) ? [] : $context['data']
60
+                sprintf( 'gravityview_log_%s_test', $action ),
61
+                $this->interpolate( $message, $context ),
62
+                empty( $context[ 'data' ] ) ? [ ] : $context[ 'data' ]
63 63
             );
64 64
         }
65 65
 
66 66
         do_action(
67
-            sprintf('gravityview_log_%s', $action),
68
-            $this->interpolate($message, $context),
69
-            empty($context['data']) ? [] : $context['data']
67
+            sprintf( 'gravityview_log_%s', $action ),
68
+            $this->interpolate( $message, $context ),
69
+            empty( $context[ 'data' ] ) ? [ ] : $context[ 'data' ]
70 70
         );
71 71
     }
72 72
 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -12,8 +12,7 @@  discard block
 block discarded – undo
12 12
  *
13 13
  * Uses the old logging stuff for now.
14 14
  */
15
-class WP_Action_Logger extends Logger
16
-{
15
+class WP_Action_Logger extends Logger {
17 16
     /**
18 17
      * Logs with an arbitrary level using `do_action` and our
19 18
      *  old action handlers.
@@ -26,8 +25,7 @@  discard block
 block discarded – undo
26 25
      *
27 26
      * @return void
28 27
      */
29
-    protected function log($level, $message, $context)
30
-    {
28
+    protected function log($level, $message, $context) {
31 29
         $php_version = (!empty($GLOBALS['GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE'])) ?
32 30
             $GLOBALS['GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE'] : phpversion();
33 31
 
Please login to merge, or discard this patch.
future/includes/class-gv-logger.php 3 patches
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 
5 5
 /** If this file is called directly, abort. */
6 6
 if (!defined('GRAVITYVIEW_DIR')) {
7
-    exit();
7
+	exit();
8 8
 }
9 9
 
10 10
 /**
@@ -12,14 +12,14 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class LogLevel
14 14
 {
15
-    const EMERGENCY = 'emergency';
16
-    const ALERT = 'alert';
17
-    const CRITICAL = 'critical';
18
-    const ERROR = 'error';
19
-    const WARNING = 'warning';
20
-    const NOTICE = 'notice';
21
-    const INFO = 'info';
22
-    const DEBUG = 'debug';
15
+	const EMERGENCY = 'emergency';
16
+	const ALERT = 'alert';
17
+	const CRITICAL = 'critical';
18
+	const ERROR = 'error';
19
+	const WARNING = 'warning';
20
+	const NOTICE = 'notice';
21
+	const INFO = 'info';
22
+	const DEBUG = 'debug';
23 23
 }
24 24
 
25 25
 /**
@@ -32,139 +32,139 @@  discard block
 block discarded – undo
32 32
  */
33 33
 abstract class Logger /** @todo extends Psr\Log\AbstractLogger */
34 34
 {
35
-    /**
36
-     * System is unusable.
37
-     *
38
-     * @param string $message
39
-     * @param array  $context
40
-     *
41
-     * @return void
42
-     */
43
-    public function emergency($message, array $context = [])
44
-    {
45
-        $this->log(LogLevel::EMERGENCY, $message, $context);
46
-    }
35
+	/**
36
+	 * System is unusable.
37
+	 *
38
+	 * @param string $message
39
+	 * @param array  $context
40
+	 *
41
+	 * @return void
42
+	 */
43
+	public function emergency($message, array $context = [])
44
+	{
45
+		$this->log(LogLevel::EMERGENCY, $message, $context);
46
+	}
47 47
 
48
-    /**
49
-     * Action must be taken immediately.
50
-     *
51
-     * Example: Entire website down, database unavailable, etc. This should
52
-     * trigger the SMS alerts and wake you up.
53
-     *
54
-     * @param string $message
55
-     * @param array  $context
56
-     *
57
-     * @return void
58
-     */
59
-    public function alert($message, array $context = [])
60
-    {
61
-        $this->log(LogLevel::ALERT, $message, $context);
62
-    }
48
+	/**
49
+	 * Action must be taken immediately.
50
+	 *
51
+	 * Example: Entire website down, database unavailable, etc. This should
52
+	 * trigger the SMS alerts and wake you up.
53
+	 *
54
+	 * @param string $message
55
+	 * @param array  $context
56
+	 *
57
+	 * @return void
58
+	 */
59
+	public function alert($message, array $context = [])
60
+	{
61
+		$this->log(LogLevel::ALERT, $message, $context);
62
+	}
63 63
 
64
-    /**
65
-     * Critical conditions.
66
-     *
67
-     * Example: Application component unavailable, unexpected exception.
68
-     *
69
-     * @param string $message
70
-     * @param array  $context
71
-     *
72
-     * @return void
73
-     */
74
-    public function critical($message, array $context = [])
75
-    {
76
-        $this->log(LogLevel::CRITICAL, $message, $context);
77
-    }
64
+	/**
65
+	 * Critical conditions.
66
+	 *
67
+	 * Example: Application component unavailable, unexpected exception.
68
+	 *
69
+	 * @param string $message
70
+	 * @param array  $context
71
+	 *
72
+	 * @return void
73
+	 */
74
+	public function critical($message, array $context = [])
75
+	{
76
+		$this->log(LogLevel::CRITICAL, $message, $context);
77
+	}
78 78
 
79
-    /**
80
-     * Runtime errors that do not require immediate action but should typically
81
-     * be logged and monitored.
82
-     *
83
-     * @param string $message
84
-     * @param array  $context
85
-     *
86
-     * @return void
87
-     */
88
-    public function error($message, array $context = [])
89
-    {
90
-        $this->log(LogLevel::ERROR, $message, $context);
91
-    }
79
+	/**
80
+	 * Runtime errors that do not require immediate action but should typically
81
+	 * be logged and monitored.
82
+	 *
83
+	 * @param string $message
84
+	 * @param array  $context
85
+	 *
86
+	 * @return void
87
+	 */
88
+	public function error($message, array $context = [])
89
+	{
90
+		$this->log(LogLevel::ERROR, $message, $context);
91
+	}
92 92
 
93
-    /**
94
-     * Exceptional occurrences that are not errors.
95
-     *
96
-     * Example: Use of deprecated APIs, poor use of an API, undesirable things
97
-     * that are not necessarily wrong.
98
-     *
99
-     * @param string $message
100
-     * @param array  $context
101
-     *
102
-     * @return void
103
-     */
104
-    public function warning($message, array $context = [])
105
-    {
106
-        $this->log(LogLevel::WARNING, $message, $context);
107
-    }
93
+	/**
94
+	 * Exceptional occurrences that are not errors.
95
+	 *
96
+	 * Example: Use of deprecated APIs, poor use of an API, undesirable things
97
+	 * that are not necessarily wrong.
98
+	 *
99
+	 * @param string $message
100
+	 * @param array  $context
101
+	 *
102
+	 * @return void
103
+	 */
104
+	public function warning($message, array $context = [])
105
+	{
106
+		$this->log(LogLevel::WARNING, $message, $context);
107
+	}
108 108
 
109
-    /**
110
-     * Normal but significant events.
111
-     *
112
-     * @param string $message
113
-     * @param array  $context
114
-     *
115
-     * @return void
116
-     */
117
-    public function notice($message, array $context = [])
118
-    {
119
-        $this->log(LogLevel::NOTICE, $message, $context);
120
-    }
109
+	/**
110
+	 * Normal but significant events.
111
+	 *
112
+	 * @param string $message
113
+	 * @param array  $context
114
+	 *
115
+	 * @return void
116
+	 */
117
+	public function notice($message, array $context = [])
118
+	{
119
+		$this->log(LogLevel::NOTICE, $message, $context);
120
+	}
121 121
 
122
-    /**
123
-     * Interesting events.
124
-     *
125
-     * Example: User logs in, SQL logs.
126
-     *
127
-     * @param string $message
128
-     * @param array  $context
129
-     *
130
-     * @return void
131
-     */
132
-    public function info($message, array $context = [])
133
-    {
134
-        $this->log(LogLevel::INFO, $message, $context);
135
-    }
122
+	/**
123
+	 * Interesting events.
124
+	 *
125
+	 * Example: User logs in, SQL logs.
126
+	 *
127
+	 * @param string $message
128
+	 * @param array  $context
129
+	 *
130
+	 * @return void
131
+	 */
132
+	public function info($message, array $context = [])
133
+	{
134
+		$this->log(LogLevel::INFO, $message, $context);
135
+	}
136 136
 
137
-    /**
138
-     * Detailed debug information.
139
-     *
140
-     * @param string $message
141
-     * @param array  $context
142
-     *
143
-     * @return void
144
-     */
145
-    public function debug($message, array $context = [])
146
-    {
147
-        $this->log(LogLevel::DEBUG, $message, $context);
148
-    }
137
+	/**
138
+	 * Detailed debug information.
139
+	 *
140
+	 * @param string $message
141
+	 * @param array  $context
142
+	 *
143
+	 * @return void
144
+	 */
145
+	public function debug($message, array $context = [])
146
+	{
147
+		$this->log(LogLevel::DEBUG, $message, $context);
148
+	}
149 149
 
150
-    /**
151
-     * Bake the context into { } placeholders in the message.
152
-     *
153
-     * @param string $message
154
-     * @param array  $context
155
-     *
156
-     * @return string The baked message;
157
-     */
158
-    protected function interpolate($message, $context)
159
-    {
160
-        foreach ($context as $key => $val) {
161
-            if (strpos($message, "{{$key}}") !== false) {
162
-                $message = str_replace("{{$key}}", $val, $message);
163
-            }
164
-        }
150
+	/**
151
+	 * Bake the context into { } placeholders in the message.
152
+	 *
153
+	 * @param string $message
154
+	 * @param array  $context
155
+	 *
156
+	 * @return string The baked message;
157
+	 */
158
+	protected function interpolate($message, $context)
159
+	{
160
+		foreach ($context as $key => $val) {
161
+			if (strpos($message, "{{$key}}") !== false) {
162
+				$message = str_replace("{{$key}}", $val, $message);
163
+			}
164
+		}
165 165
 
166
-        return $message;
167
-    }
166
+		return $message;
167
+	}
168 168
 }
169 169
 
170 170
 /** Load implementations. */
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 namespace GV;
4 4
 
5 5
 /** If this file is called directly, abort. */
6
-if (!defined('GRAVITYVIEW_DIR')) {
6
+if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
7 7
     exit();
8 8
 }
9 9
 
@@ -40,9 +40,9 @@  discard block
 block discarded – undo
40 40
      *
41 41
      * @return void
42 42
      */
43
-    public function emergency($message, array $context = [])
43
+    public function emergency( $message, array $context = [ ] )
44 44
     {
45
-        $this->log(LogLevel::EMERGENCY, $message, $context);
45
+        $this->log( LogLevel::EMERGENCY, $message, $context );
46 46
     }
47 47
 
48 48
     /**
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
      *
57 57
      * @return void
58 58
      */
59
-    public function alert($message, array $context = [])
59
+    public function alert( $message, array $context = [ ] )
60 60
     {
61
-        $this->log(LogLevel::ALERT, $message, $context);
61
+        $this->log( LogLevel::ALERT, $message, $context );
62 62
     }
63 63
 
64 64
     /**
@@ -71,9 +71,9 @@  discard block
 block discarded – undo
71 71
      *
72 72
      * @return void
73 73
      */
74
-    public function critical($message, array $context = [])
74
+    public function critical( $message, array $context = [ ] )
75 75
     {
76
-        $this->log(LogLevel::CRITICAL, $message, $context);
76
+        $this->log( LogLevel::CRITICAL, $message, $context );
77 77
     }
78 78
 
79 79
     /**
@@ -85,9 +85,9 @@  discard block
 block discarded – undo
85 85
      *
86 86
      * @return void
87 87
      */
88
-    public function error($message, array $context = [])
88
+    public function error( $message, array $context = [ ] )
89 89
     {
90
-        $this->log(LogLevel::ERROR, $message, $context);
90
+        $this->log( LogLevel::ERROR, $message, $context );
91 91
     }
92 92
 
93 93
     /**
@@ -101,9 +101,9 @@  discard block
 block discarded – undo
101 101
      *
102 102
      * @return void
103 103
      */
104
-    public function warning($message, array $context = [])
104
+    public function warning( $message, array $context = [ ] )
105 105
     {
106
-        $this->log(LogLevel::WARNING, $message, $context);
106
+        $this->log( LogLevel::WARNING, $message, $context );
107 107
     }
108 108
 
109 109
     /**
@@ -114,9 +114,9 @@  discard block
 block discarded – undo
114 114
      *
115 115
      * @return void
116 116
      */
117
-    public function notice($message, array $context = [])
117
+    public function notice( $message, array $context = [ ] )
118 118
     {
119
-        $this->log(LogLevel::NOTICE, $message, $context);
119
+        $this->log( LogLevel::NOTICE, $message, $context );
120 120
     }
121 121
 
122 122
     /**
@@ -129,9 +129,9 @@  discard block
 block discarded – undo
129 129
      *
130 130
      * @return void
131 131
      */
132
-    public function info($message, array $context = [])
132
+    public function info( $message, array $context = [ ] )
133 133
     {
134
-        $this->log(LogLevel::INFO, $message, $context);
134
+        $this->log( LogLevel::INFO, $message, $context );
135 135
     }
136 136
 
137 137
     /**
@@ -142,9 +142,9 @@  discard block
 block discarded – undo
142 142
      *
143 143
      * @return void
144 144
      */
145
-    public function debug($message, array $context = [])
145
+    public function debug( $message, array $context = [ ] )
146 146
     {
147
-        $this->log(LogLevel::DEBUG, $message, $context);
147
+        $this->log( LogLevel::DEBUG, $message, $context );
148 148
     }
149 149
 
150 150
     /**
@@ -155,11 +155,11 @@  discard block
 block discarded – undo
155 155
      *
156 156
      * @return string The baked message;
157 157
      */
158
-    protected function interpolate($message, $context)
158
+    protected function interpolate( $message, $context )
159 159
     {
160
-        foreach ($context as $key => $val) {
161
-            if (strpos($message, "{{$key}}") !== false) {
162
-                $message = str_replace("{{$key}}", $val, $message);
160
+        foreach ( $context as $key => $val ) {
161
+            if ( strpos( $message, "{{$key}}" ) !== false ) {
162
+                $message = str_replace( "{{$key}}", $val, $message );
163 163
             }
164 164
         }
165 165
 
@@ -168,4 +168,4 @@  discard block
 block discarded – undo
168 168
 }
169 169
 
170 170
 /** Load implementations. */
171
-require gravityview()->plugin->dir('future/includes/class-gv-logger-wp-action.php');
171
+require gravityview()->plugin->dir( 'future/includes/class-gv-logger-wp-action.php' );
Please login to merge, or discard this patch.
Braces   +11 added lines, -22 removed lines patch added patch discarded remove patch
@@ -10,8 +10,7 @@  discard block
 block discarded – undo
10 10
 /**
11 11
  * Describes log levels.
12 12
  */
13
-class LogLevel
14
-{
13
+class LogLevel {
15 14
     const EMERGENCY = 'emergency';
16 15
     const ALERT = 'alert';
17 16
     const CRITICAL = 'critical';
@@ -30,8 +29,7 @@  discard block
 block discarded – undo
30 29
  * @see https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md
31 30
  * @see https://github.com/php-fig/log/blob/master/Psr/Log/AbstractLogger.php
32 31
  */
33
-abstract class Logger /** @todo extends Psr\Log\AbstractLogger */
34
-{
32
+abstract class Logger /** @todo extends Psr\Log\AbstractLogger */ {
35 33
     /**
36 34
      * System is unusable.
37 35
      *
@@ -40,8 +38,7 @@  discard block
 block discarded – undo
40 38
      *
41 39
      * @return void
42 40
      */
43
-    public function emergency($message, array $context = [])
44
-    {
41
+    public function emergency($message, array $context = []) {
45 42
         $this->log(LogLevel::EMERGENCY, $message, $context);
46 43
     }
47 44
 
@@ -56,8 +53,7 @@  discard block
 block discarded – undo
56 53
      *
57 54
      * @return void
58 55
      */
59
-    public function alert($message, array $context = [])
60
-    {
56
+    public function alert($message, array $context = []) {
61 57
         $this->log(LogLevel::ALERT, $message, $context);
62 58
     }
63 59
 
@@ -71,8 +67,7 @@  discard block
 block discarded – undo
71 67
      *
72 68
      * @return void
73 69
      */
74
-    public function critical($message, array $context = [])
75
-    {
70
+    public function critical($message, array $context = []) {
76 71
         $this->log(LogLevel::CRITICAL, $message, $context);
77 72
     }
78 73
 
@@ -85,8 +80,7 @@  discard block
 block discarded – undo
85 80
      *
86 81
      * @return void
87 82
      */
88
-    public function error($message, array $context = [])
89
-    {
83
+    public function error($message, array $context = []) {
90 84
         $this->log(LogLevel::ERROR, $message, $context);
91 85
     }
92 86
 
@@ -101,8 +95,7 @@  discard block
 block discarded – undo
101 95
      *
102 96
      * @return void
103 97
      */
104
-    public function warning($message, array $context = [])
105
-    {
98
+    public function warning($message, array $context = []) {
106 99
         $this->log(LogLevel::WARNING, $message, $context);
107 100
     }
108 101
 
@@ -114,8 +107,7 @@  discard block
 block discarded – undo
114 107
      *
115 108
      * @return void
116 109
      */
117
-    public function notice($message, array $context = [])
118
-    {
110
+    public function notice($message, array $context = []) {
119 111
         $this->log(LogLevel::NOTICE, $message, $context);
120 112
     }
121 113
 
@@ -129,8 +121,7 @@  discard block
 block discarded – undo
129 121
      *
130 122
      * @return void
131 123
      */
132
-    public function info($message, array $context = [])
133
-    {
124
+    public function info($message, array $context = []) {
134 125
         $this->log(LogLevel::INFO, $message, $context);
135 126
     }
136 127
 
@@ -142,8 +133,7 @@  discard block
 block discarded – undo
142 133
      *
143 134
      * @return void
144 135
      */
145
-    public function debug($message, array $context = [])
146
-    {
136
+    public function debug($message, array $context = []) {
147 137
         $this->log(LogLevel::DEBUG, $message, $context);
148 138
     }
149 139
 
@@ -155,8 +145,7 @@  discard block
 block discarded – undo
155 145
      *
156 146
      * @return string The baked message;
157 147
      */
158
-    protected function interpolate($message, $context)
159
-    {
148
+    protected function interpolate($message, $context) {
160 149
         foreach ($context as $key => $val) {
161 150
             if (strpos($message, "{{$key}}") !== false) {
162 151
                 $message = str_replace("{{$key}}", $val, $message);
Please login to merge, or discard this patch.
future/includes/class-gv-renderer-entry-edit.php 3 patches
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 
5 5
 /** If this file is called directly, abort. */
6 6
 if (!defined('GRAVITYVIEW_DIR')) {
7
-    exit();
7
+	exit();
8 8
 }
9 9
 
10 10
 /**
@@ -14,36 +14,36 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class Edit_Entry_Renderer extends Entry_Renderer
16 16
 {
17
-    /**
18
-     * Renders a an editable \GV\Entry instance.
19
-     *
20
-     * @param \GV\Entry   $entry   The Entry instance to render.
21
-     * @param \GV\View    $view    The View connected to the entry.
22
-     * @param \GV\Request $request The request context we're currently in. Default: `gravityview()->request`
23
-     *
24
-     * @todo Just a wrapper around the old code. Cheating. Needs rewrite :)
25
-     *
26
-     * @api
27
-     *
28
-     * @since 2.0
29
-     *
30
-     * @return string The rendered Entry edit screen.
31
-     */
32
-    public function render(Entry $entry, View $view, Request $request = null)
33
-    {
34
-        $entries = new \GV\Entry_Collection();
35
-        $entries->add($entry);
17
+	/**
18
+	 * Renders a an editable \GV\Entry instance.
19
+	 *
20
+	 * @param \GV\Entry   $entry   The Entry instance to render.
21
+	 * @param \GV\View    $view    The View connected to the entry.
22
+	 * @param \GV\Request $request The request context we're currently in. Default: `gravityview()->request`
23
+	 *
24
+	 * @todo Just a wrapper around the old code. Cheating. Needs rewrite :)
25
+	 *
26
+	 * @api
27
+	 *
28
+	 * @since 2.0
29
+	 *
30
+	 * @return string The rendered Entry edit screen.
31
+	 */
32
+	public function render(Entry $entry, View $view, Request $request = null)
33
+	{
34
+		$entries = new \GV\Entry_Collection();
35
+		$entries->add($entry);
36 36
 
37
-        \GV\Mocks\Legacy_Context::push([
38
-            'view'    => $view,
39
-            'entries' => $entries,
40
-        ]);
37
+		\GV\Mocks\Legacy_Context::push([
38
+			'view'    => $view,
39
+			'entries' => $entries,
40
+		]);
41 41
 
42
-        ob_start();
43
-        do_action('gravityview_edit_entry', null, $entry, $view, $request);
42
+		ob_start();
43
+		do_action('gravityview_edit_entry', null, $entry, $view, $request);
44 44
 
45
-        \GV\Mocks\Legacy_Context::pop();
45
+		\GV\Mocks\Legacy_Context::pop();
46 46
 
47
-        return ob_get_clean();
48
-    }
47
+		return ob_get_clean();
48
+	}
49 49
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 namespace GV;
4 4
 
5 5
 /** If this file is called directly, abort. */
6
-if (!defined('GRAVITYVIEW_DIR')) {
6
+if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
7 7
     exit();
8 8
 }
9 9
 
@@ -29,18 +29,18 @@  discard block
 block discarded – undo
29 29
      *
30 30
      * @return string The rendered Entry edit screen.
31 31
      */
32
-    public function render(Entry $entry, View $view, Request $request = null)
32
+    public function render( Entry $entry, View $view, Request $request = null )
33 33
     {
34 34
         $entries = new \GV\Entry_Collection();
35
-        $entries->add($entry);
35
+        $entries->add( $entry );
36 36
 
37
-        \GV\Mocks\Legacy_Context::push([
37
+        \GV\Mocks\Legacy_Context::push( [
38 38
             'view'    => $view,
39 39
             'entries' => $entries,
40
-        ]);
40
+        ] );
41 41
 
42 42
         ob_start();
43
-        do_action('gravityview_edit_entry', null, $entry, $view, $request);
43
+        do_action( 'gravityview_edit_entry', null, $entry, $view, $request );
44 44
 
45 45
         \GV\Mocks\Legacy_Context::pop();
46 46
 
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -12,8 +12,7 @@  discard block
 block discarded – undo
12 12
  *
13 13
  * The edit entry renderer.
14 14
  */
15
-class Edit_Entry_Renderer extends Entry_Renderer
16
-{
15
+class Edit_Entry_Renderer extends Entry_Renderer {
17 16
     /**
18 17
      * Renders a an editable \GV\Entry instance.
19 18
      *
@@ -29,8 +28,7 @@  discard block
 block discarded – undo
29 28
      *
30 29
      * @return string The rendered Entry edit screen.
31 30
      */
32
-    public function render(Entry $entry, View $view, Request $request = null)
33
-    {
31
+    public function render(Entry $entry, View $view, Request $request = null) {
34 32
         $entries = new \GV\Entry_Collection();
35 33
         $entries->add($entry);
36 34
 
Please login to merge, or discard this patch.
future/includes/class-gv-context.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@
 block discarded – undo
4 4
 
5 5
 /** If this file is called directly, abort. */
6 6
 if (!defined('GRAVITYVIEW_DIR')) {
7
-    exit();
7
+	exit();
8 8
 }
9 9
 
10 10
 /**
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@
 block discarded – undo
3 3
 namespace GV;
4 4
 
5 5
 /** If this file is called directly, abort. */
6
-if (!defined('GRAVITYVIEW_DIR')) {
6
+if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
7 7
     exit();
8 8
 }
9 9
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -10,6 +10,5 @@
 block discarded – undo
10 10
 /**
11 11
  * A generic Context base class.
12 12
  */
13
-abstract class Context
14
-{
13
+abstract class Context {
15 14
 }
Please login to merge, or discard this patch.
future/includes/class-gv-template-field.php 3 patches
Indentation   +484 added lines, -484 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 
5 5
 /** If this file is called directly, abort. */
6 6
 if (!defined('GRAVITYVIEW_DIR')) {
7
-    exit();
7
+	exit();
8 8
 }
9 9
 
10 10
 /**
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  * @see https://github.com/GaryJones/Gamajo-Template-Loader
14 14
  */
15 15
 if (!class_exists('\GV\Gamajo_Template_Loader')) {
16
-    require gravityview()->plugin->dir('future/lib/class-gamajo-template-loader.php');
16
+	require gravityview()->plugin->dir('future/lib/class-gamajo-template-loader.php');
17 17
 }
18 18
 
19 19
 /**
@@ -23,488 +23,488 @@  discard block
 block discarded – undo
23 23
  */
24 24
 abstract class Field_Template extends Template
25 25
 {
26
-    /**
27
-     * Prefix for filter names.
28
-     *
29
-     * @var string
30
-     */
31
-    protected $filter_prefix = 'gravityview/template/fields';
32
-
33
-    /**
34
-     * Directory name where custom templates for this plugin should be found in the theme.
35
-     *
36
-     * @var string
37
-     */
38
-    protected $theme_template_directory = 'gravityview/fields/';
39
-
40
-    /**
41
-     * Directory name where the default templates for this plugin are found.
42
-     *
43
-     * @var string
44
-     */
45
-    protected $plugin_template_directory = 'templates/fields/';
46
-
47
-    /**
48
-     * @var \GV\Field The field connected to this template.
49
-     */
50
-    public $field;
51
-
52
-    /**
53
-     * @var \GV\View The view context.
54
-     */
55
-    public $view;
56
-
57
-    /**
58
-     * @var \GV\Source The source context.
59
-     */
60
-    public $source;
61
-
62
-    /**
63
-     * @var \GV\Entry The entry context.
64
-     */
65
-    public $entry;
66
-
67
-    /**
68
-     * @var \GV\Request The request context.
69
-     */
70
-    public $request;
71
-
72
-    /**
73
-     * @var string The template slug to be loaded (like "table", "list")
74
-     */
75
-    public static $slug;
76
-
77
-    /**
78
-     * Initializer.
79
-     *
80
-     * @param \GV\Field   $field   The field about to be rendered.
81
-     * @param \GV\View    $view    The view in this context, if applicable.
82
-     * @param \GV\Source  $source  The source (form) in this context, if applicable.
83
-     * @param \GV\Entry   $entry   The entry in this context, if applicable.
84
-     * @param \GV\Request $request The request in this context, if applicable.
85
-     */
86
-    public function __construct(Field $field, View $view = null, Source $source = null, Entry $entry = null, Request $request = null)
87
-    {
88
-        $this->field = $field;
89
-        $this->view = $view;
90
-        $this->source = $source;
91
-        $this->entry = $entry;
92
-        $this->request = $request;
93
-
94
-        /** Add granular overrides. */
95
-        add_filter($this->filter_prefix.'_get_template_part', $this->_add_id_specific_templates_callback = self::add_id_specific_templates($this), 10, 3);
96
-
97
-        parent::__construct();
98
-    }
99
-
100
-    public function __destruct()
101
-    {
102
-        remove_filter($this->filter_prefix.'_get_template_part', $this->_add_id_specific_templates_callback);
103
-    }
104
-
105
-    /**
106
-     * Enable granular template overrides based on current post, view, form, field types, etc.
107
-     *
108
-     * Why? See https://github.com/gravityview/GravityView/issues/1024
109
-     *
110
-     * @param \GV\Field_Template $template The template instance.
111
-     *
112
-     * @return callable The callback bound to `get_template_part`. See `\GV\Field_Template::__construct`
113
-     */
114
-    public static function add_id_specific_templates($template)
115
-    {
116
-        $inputType = null;
117
-        $field_type = null;
118
-        $field_id = null;
119
-        $view_id = null;
120
-        $form_id = null;
121
-        $is_view = $template->request && $template->request->is_view();
122
-
123
-        if ($template->field) {
124
-            $inputType = $template->field->inputType;
125
-            $field_type = $template->field->type;
126
-            $field_id = $template->field->ID;
127
-        }
128
-
129
-        if ($template->view) {
130
-            $view_id = $template->view->ID;
131
-            $form_id = $template->view->form ? $template->view->form->ID : null;
132
-        }
133
-
134
-        $class = get_class($template);
135
-
136
-        /**
137
-         * Enable granular template overrides based on current post, view, form, field types, etc.
138
-         *
139
-         * The hierarchy is as follows:
140
-         *
141
-         * - post-[ID of post of page where view is embedded]-view-[View ID]-field-[Field type]-html.php
142
-         * - post-[ID of post of page where view is embedded]-view-[View ID]-field-[Field inputType]-html.php
143
-         * - post-[ID of post of page where view is embedded]-view-[View ID]-field-html.php
144
-         * - post-[ID of post of page where view is embedded]-field-[Field type]-html.php
145
-         * - post-[ID of post of page where view is embedded]-field-[Field inputType]-html.php
146
-         * - post-[ID of post of page where view is embedded]-field-html.php
147
-         * - post-[ID of post of page where view is embedded]-view-[View ID]-field-[Field type].php
148
-         * - post-[ID of post of page where view is embedded]-view-[View ID]-field-[Field inputType].php
149
-         * - post-[ID of post of page where view is embedded]-view-[View ID]-field.php
150
-         * - post-[ID of post of page where view is embedded]-field-[Field type].php
151
-         * - post-[ID of post of page where view is embedded]-field-[Field inputType].php
152
-         * - post-[ID of post of page where view is embedded]-field.php
153
-         * - form-[Form ID]-field-[Field ID]-html.php
154
-         * - form-[Form ID]-field-[Field ID].php
155
-         * - form-[Form ID]-field-[Field type]-html.php
156
-         * - form-[Form ID]-field-[Field inputType]-html.php
157
-         * - form-[Form ID]-field-[Field type].php
158
-         * - form-[Form ID]-field-[Field inputType].php
159
-         * - view-[View ID]-field-[Field type]-html.php
160
-         * - view-[View ID]-field-[Field inputType]-html.php
161
-         * - view-[View ID]-field-[Field type].php
162
-         * - view-[View ID]-field-[Field inputType].php
163
-         * - field-[Field type]-html.php
164
-         * - field-[Field inputType]-html.php
165
-         * - field-[Field type].php
166
-         * - field-[Field inputType].php
167
-         * - field-html.php
168
-         * - field.php
169
-         *
170
-         * @see  Gamajo_Template_Loader::get_template_file_names() Where the filter is
171
-         *
172
-         * @param array  $templates Existing list of templates.
173
-         * @param string $slug      Name of the template base, example: `html`, `json`, `xml`
174
-         * @param string $name      Name of the template part.
175
-         *
176
-         * @return array $templates Modified template array, merged with existing $templates values
177
-         */
178
-        return function ($templates, $slug, $name) use ($class, $inputType, $field_type, $view_id, $is_view, $form_id, $field_id) {
179
-            $specifics = [];
180
-
181
-            list($slug_dir, $slug_name) = $class::split_slug($slug, $name);
182
-
183
-            global $post;
184
-
185
-            if ($is_view && $post) {
186
-                if ($field_type) {
187
-                    $specifics[] = sprintf('%spost-%d-view-%d-field-%s-%s.php', $slug_dir, $post->ID, $view_id, $field_type, $slug_name);
188
-                    $inputType && $specifics[] = sprintf('%spost-%d-view-%d-field-%s-%s.php', $slug_dir, $post->ID, $view_id, $inputType, $slug_name);
189
-                    $specifics[] = sprintf('%spost-%d-view-%d-field-%s.php', $slug_dir, $post->ID, $view_id, $field_type);
190
-                    $inputType && $specifics[] = sprintf('%spost-%d-view-%d-field-%s.php', $slug_dir, $post->ID, $view_id, $inputType);
191
-                    $specifics[] = sprintf('%spost-%d-field-%s-%s.php', $slug_dir, $post->ID, $field_type, $slug_name);
192
-                    $inputType && $specifics[] = sprintf('%spost-%d-field-%s-%s.php', $slug_dir, $post->ID, $inputType, $slug_name);
193
-                    $specifics[] = sprintf('%spost-%d-field-%s.php', $slug_dir, $post->ID, $field_type);
194
-                    $inputType && $specifics[] = sprintf('%spost-%d-field-%s.php', $slug_dir, $post->ID, $inputType);
195
-                }
196
-
197
-                $specifics[] = sprintf('%spost-%d-view-%d-field-%s.php', $slug_dir, $post->ID, $view_id, $slug_name);
198
-                $specifics[] = sprintf('%spost-%d-view-%d-field.php', $slug_dir, $post->ID, $view_id);
199
-                $specifics[] = sprintf('%spost-%d-field-%s.php', $slug_dir, $post->ID, $slug_name);
200
-                $specifics[] = sprintf('%spost-%d-field.php', $slug_dir, $post->ID);
201
-            }
202
-
203
-            /** Field-specific */
204
-            if ($field_id && $form_id) {
205
-                if ($field_id) {
206
-                    $specifics[] = sprintf('%sform-%d-field-%d-%s.php', $slug_dir, $form_id, $field_id, $slug_name);
207
-                    $specifics[] = sprintf('%sform-%d-field-%d.php', $slug_dir, $form_id, $field_id);
208
-
209
-                    if ($view_id) {
210
-                        $specifics[] = sprintf('%sview-%d-field-%d.php', $slug_dir, $view_id, $field_id);
211
-                    }
212
-                }
213
-
214
-                if ($field_type) {
215
-                    $specifics[] = sprintf('%sform-%d-field-%s-%s.php', $slug_dir, $form_id, $field_type, $slug_name);
216
-                    $inputType && $specifics[] = sprintf('%sform-%d-field-%s-%s.php', $slug_dir, $form_id, $inputType, $slug_name);
217
-                    $specifics[] = sprintf('%sform-%d-field-%s.php', $slug_dir, $form_id, $field_type);
218
-                    $inputType && $specifics[] = sprintf('%sform-%d-field-%s.php', $slug_dir, $form_id, $inputType);
219
-
220
-                    $specifics[] = sprintf('%sview-%d-field-%s-%s.php', $slug_dir, $view_id, $field_type, $slug_name);
221
-                    $inputType && $specifics[] = sprintf('%sview-%d-field-%s-%s.php', $slug_dir, $view_id, $inputType, $slug_name);
222
-                    $specifics[] = sprintf('%sview-%d-field-%s.php', $slug_dir, $view_id, $field_type);
223
-                    $inputType && $specifics[] = sprintf('%sview-%d-field-%s.php', $slug_dir, $view_id, $inputType);
224
-
225
-                    $specifics[] = sprintf('%sfield-%s-%s.php', $slug_dir, $field_type, $slug_name);
226
-                    $inputType && $specifics[] = sprintf('%sfield-%s-%s.php', $slug_dir, $inputType, $slug_name);
227
-                    $specifics[] = sprintf('%sfield-%s.php', $slug_dir, $field_type);
228
-                    $inputType && $specifics[] = sprintf('%sfield-%s.php', $slug_dir, $inputType);
229
-                }
230
-            }
231
-
232
-            if ($form_id) {
233
-                /** Generic field templates */
234
-                $specifics[] = sprintf('%sview-%d-field-%s.php', $slug_dir, $view_id, $slug_name);
235
-                $specifics[] = sprintf('%sform-%d-field-%s.php', $slug_dir, $form_id, $slug_name);
236
-
237
-                $specifics[] = sprintf('%sview-%d-field.php', $slug_dir, $view_id);
238
-                $specifics[] = sprintf('%sform-%d-field.php', $slug_dir, $form_id);
239
-            }
240
-
241
-            /**
242
-             * Legacy.
243
-             * Ignore some types that conflict.
244
-             */
245
-            if (!in_array($field_type, ['notes'])) {
246
-                $specifics[] = sprintf('%s.php', $field_type);
247
-                $specifics[] = sprintf('fields/%s.php', $field_type);
248
-            }
249
-
250
-            $specifics[] = sprintf('%sfield-%s.php', $slug_dir, $slug_name);
251
-            $specifics[] = sprintf('%sfield.php', $slug_dir);
252
-
253
-            return array_merge($specifics, $templates);
254
-        };
255
-    }
256
-
257
-    /**
258
-     * Output some HTML.
259
-     *
260
-     * @todo Move to \GV\Field_HTML_Template, but call filters here?
261
-     *
262
-     * @return void
263
-     */
264
-    public function render()
265
-    {
266
-        if (!$entry = $this->entry->from_field($this->field)) {
267
-            gravityview()->log->error('Entry is invalid for field. Returning empty.');
268
-
269
-            return;
270
-        }
271
-
272
-        /** Retrieve the value. */
273
-        $display_value = $value = $this->field->get_value($this->view, $this->source, $entry);
274
-
275
-        $source = $this->source;
276
-        $source_backend = $source ? $source::$backend : null;
277
-
278
-        \GV\Mocks\Legacy_Context::load([
279
-            'field' => $this->field,
280
-        ]);
281
-
282
-        /** Alter the display value according to Gravity Forms. */
283
-        if (\GV\Source::BACKEND_GRAVITYFORMS === $source_backend && !$this->field instanceof Internal_Field) {
284
-
285
-            /** Prevent any PHP warnings that may be generated. */
286
-            ob_start();
287
-
288
-            $display_value = \GFCommon::get_lead_field_display($this->field->field, $value, $entry['currency'], false, 'html');
289
-
290
-            if ($errors = ob_get_clean()) {
291
-                gravityview()->log->error('Errors when calling GFCommon::get_lead_field_display()', ['data' => $errors]);
292
-            }
293
-
294
-            // `gform_entry_field_value` expects a GF_Field, but $this->field->field can be NULL
295
-            if (!$this->field->field instanceof GF_Field) {
296
-                $gf_field = \GF_Fields::create($this->field->field);
297
-            }
298
-
299
-            /** Call the Gravity Forms field value filter. */
300
-            $display_value = apply_filters('gform_entry_field_value', $display_value, $gf_field, $entry->as_entry(), $this->source->form);
301
-
302
-            unset($gf_field);
303
-
304
-            /** Replace merge tags for admin-only fields. */
305
-            if (!empty($this->field->field->adminOnly)) {
306
-                $display_value = \GravityView_API::replace_variables($display_value, $this->form->form, $entry->as_entry(), false, false);
307
-            }
308
-        }
309
-
310
-        $context = Template_Context::from_template($this, compact('display_value', 'value'));
311
-
312
-        /**
313
-         * Make various pieces of data available to the template
314
-         *  under the $gravityview scoped variable.
315
-         *
316
-         * @filter `gravityview/template/field/context`
317
-         *
318
-         * @param \GV\Template_Context $context The context for this template.
319
-         *
320
-         * @since 2.0
321
-         */
322
-        $this->push_template_data(apply_filters('gravityview/template/field/context', $context), 'gravityview');
323
-
324
-        /** Bake the template. */
325
-        ob_start();
326
-        $this->located_template = $this->get_template_part(static::$slug);
327
-        $output = ob_get_clean();
328
-
329
-        if (empty($output)) {
330
-            /**
331
-             * @filter `gravityview_empty_value` What to display when a field is empty
332
-             *
333
-             * @deprecated Use the `gravityview/field/value/empty` filter instead
334
-             *
335
-             * @param string $value (empty string)
336
-             */
337
-            $output = apply_filters('gravityview_empty_value', $output);
338
-
339
-            /**
340
-             * @filter `gravityview/field/value/empty` What to display when this field is empty.
341
-             *
342
-             * @param string $value The value to display (Default: empty string)
343
-             * @param \GV\Template_Context The template context this is being called from.
344
-             */
345
-            $output = apply_filters('gravityview/field/value/empty', $output, Template_Context::from_template($this));
346
-
347
-            $context = Template_Context::from_template($this, compact('display_value', 'value'));
348
-        }
349
-
350
-        gravityview()->log->info('Field template for field #{field_id} loaded: {located_template}', ['field_id' => $this->field->ID, 'located_template' => $this->located_template]);
351
-
352
-        $this->pop_template_data('gravityview');
353
-
354
-        /** A compatibility array that's required by some of the deprecated filters. */
355
-        $field_compat = [
356
-            'form'           => $source_backend == \GV\Source::BACKEND_GRAVITYFORMS ? $this->source->form : ($this->view->form ? $this->view->form->form : null),
357
-            'field_id'       => $this->field->ID,
358
-            'field'          => $this->field->field,
359
-            'field_settings' => $this->field->as_configuration(),
360
-            'value'          => $value,
361
-            'display_value'  => $display_value,
362
-            'format'         => 'html',
363
-            'entry'          => $entry->as_entry(),
364
-            'field_type'     => $this->field->type,
365
-            'field_path'     => $this->located_template,
366
-        ];
367
-
368
-        /**
369
-         * Wrap output in a link, if enabled in the field settings.
370
-         *
371
-         * @todo Cleanup
372
-         *
373
-         * @param string               $output  HTML value output
374
-         * @param \GV\Template_Context $context
375
-         *
376
-         * @return mixed|string|void
377
-         */
378
-        $pre_link_compat_callback = function ($output, $context) use ($field_compat) {
379
-            $field = $context->field;
380
-
381
-            /**
382
-             * @filter `gravityview_field_entry_value_{$field_type}_pre_link` Modify the field value output for a field type before Show As Link setting is applied. Example: `gravityview_field_entry_value_number_pre_link`
383
-             *
384
-             * @since 1.16
385
-             *
386
-             * @param string $output         HTML value output
387
-             * @param array  $entry          The GF entry array
388
-             * @param array  $field_settings Settings for the particular GV field
389
-             * @param array  $field          Field array, as fetched from GravityView_View::getCurrentField()
390
-             *
391
-             * @deprecated Use the `gravityview/field/{$field_type}/output` or `gravityview/field/output` filters instead.
392
-             */
393
-            $output = apply_filters("gravityview_field_entry_value_{$field->type}_pre_link", $output, $context->entry->as_entry(), $field->as_configuration(), $field_compat);
394
-
395
-            $output = apply_filters('gravityview_field_entry_value_pre_link', $output, $context->entry->as_entry(), $field->as_configuration(), $field_compat);
396
-
397
-            /**
398
-             * Link to the single entry by wrapping the output in an anchor tag.
399
-             *
400
-             * Fields can override this by modifying the field data variable inside the field. See /templates/fields/post_image.php for an example.
401
-             */
402
-            if (!empty($field->show_as_link) && !\gv_empty($output, false, false)) {
403
-                $link_atts = empty($field->new_window) ? [] : ['target' => '_blank'];
404
-
405
-                $permalink = $context->entry->get_permalink($context->view, $context->request);
406
-                $output = \gravityview_get_link($permalink, $output, $link_atts);
407
-
408
-                /**
409
-                 * @filter `gravityview_field_entry_link` Modify the link HTML
410
-                 *
411
-                 * @param string $link           HTML output of the link
412
-                 * @param string $href           URL of the link
413
-                 * @param array  $entry          The GF entry array
414
-                 * @param array  $field_settings Settings for the particular GV field
415
-                 *
416
-                 * @deprecated Use `gravityview/template/field/entry_link`
417
-                 */
418
-                $output = apply_filters('gravityview_field_entry_link', $output, $permalink, $context->entry->as_entry(), $field->as_configuration());
419
-
420
-                /**
421
-                 * @filter `gravityview/template/field/entry_link` Modify the link HTML
422
-                 *
423
-                 * @since 2.0
424
-                 *
425
-                 * @param string               $link    HTML output of the link
426
-                 * @param string               $href    URL of the link
427
-                 * @param \GV\Template_Context $context The context
428
-                 */
429
-                $output = apply_filters('gravityview/template/field/entry_link', $output, $permalink, $context);
430
-            }
431
-
432
-            return $output;
433
-        };
434
-
435
-        // TODO Cleanup
436
-        $post_link_compat_callback = function ($output, $context) use ($field_compat) {
437
-            $field = $context->field;
438
-
439
-            /**
440
-             * @filter `gravityview_field_entry_value_{$field_type}` Modify the field value output for a field type. Example: `gravityview_field_entry_value_number`
441
-             *
442
-             * @since 1.6
443
-             *
444
-             * @param string $output         HTML value output
445
-             * @param array  $entry          The GF entry array
446
-             * @param array  $field_settings Settings for the particular GV field
447
-             * @param array  $field          Current field being displayed
448
-             *
449
-             * @deprecated Use the `gravityview/field/{$field_type}/output` or `gravityview/field/output` filters instead.
450
-             */
451
-            $output = apply_filters("gravityview_field_entry_value_{$field->type}", $output, $context->entry->as_entry(), $field->as_configuration(), $field_compat);
452
-
453
-            /**
454
-             * @filter `gravityview_field_entry_value` Modify the field value output for all field types
455
-             *
456
-             * @param string $output         HTML value output
457
-             * @param array  $entry          The GF entry array
458
-             * @param array  $field_settings Settings for the particular GV field
459
-             * @param array  $field_data     {@since 1.6}
460
-             *
461
-             * @deprecated Use the `gravityview/field/{$field_type}/output` or `gravityview/field/output` filters instead.
462
-             */
463
-            $output = apply_filters('gravityview_field_entry_value', $output, $context->entry->as_entry(), $field->as_configuration(), $field_compat);
464
-
465
-            /**
466
-             * @filter `gravityview/template/field/{$field_type}/output` Modify the field output for a field type.
467
-             *
468
-             * @since 2.0
469
-             *
470
-             * @param string $output The current output.
471
-             * @param \GV\Template_Context The template context this is being called from.
472
-             */
473
-            return apply_filters("gravityview/template/field/{$field->type}/output", $output, $context);
474
-        };
475
-
476
-        /**
477
-         * Okay, what's this whole pre/post_link compat deal, huh?
478
-         *
479
-         * Well, the `gravityview_field_entry_value_{$field_type}_pre_link` filter
480
-         *  is expected to be applied before the value is turned into an entry link.
481
-         *
482
-         * And then `gravityview_field_entry_value_{$field_type}` and `gravityview_field_entry_value`
483
-         *  are called afterwards.
484
-         *
485
-         * So we're going to use filter priorities to make sure this happens inline with
486
-         *  our new filters, in the correct sequence. Pre-link called with priority 5 and
487
-         *  post-link called with priority 9. Then everything else.
488
-         *
489
-         * If a new code wants to alter the value before it is hyperlinked (hyperlinkified?),
490
-         *  it should hook into a priority between -inf. and 8. Afterwards: 10 to +inf.
491
-         */
492
-        add_filter('gravityview/template/field/output', $pre_link_compat_callback, 5, 2);
493
-        add_filter('gravityview/template/field/output', $post_link_compat_callback, 9, 2);
494
-
495
-        /**
496
-         * @filter `gravityview/template/field/output` Modify the field output for a field.
497
-         *
498
-         * @since 2.0
499
-         *
500
-         * @param string $output The current output.
501
-         * @param \GV\Template_Context The template this is being called from.
502
-         */
503
-        echo apply_filters('gravityview/template/field/output', $output, $context);
504
-
505
-        remove_filter('gravityview/template/field/output', $pre_link_compat_callback, 5);
506
-        remove_filter('gravityview/template/field/output', $post_link_compat_callback, 9);
507
-    }
26
+	/**
27
+	 * Prefix for filter names.
28
+	 *
29
+	 * @var string
30
+	 */
31
+	protected $filter_prefix = 'gravityview/template/fields';
32
+
33
+	/**
34
+	 * Directory name where custom templates for this plugin should be found in the theme.
35
+	 *
36
+	 * @var string
37
+	 */
38
+	protected $theme_template_directory = 'gravityview/fields/';
39
+
40
+	/**
41
+	 * Directory name where the default templates for this plugin are found.
42
+	 *
43
+	 * @var string
44
+	 */
45
+	protected $plugin_template_directory = 'templates/fields/';
46
+
47
+	/**
48
+	 * @var \GV\Field The field connected to this template.
49
+	 */
50
+	public $field;
51
+
52
+	/**
53
+	 * @var \GV\View The view context.
54
+	 */
55
+	public $view;
56
+
57
+	/**
58
+	 * @var \GV\Source The source context.
59
+	 */
60
+	public $source;
61
+
62
+	/**
63
+	 * @var \GV\Entry The entry context.
64
+	 */
65
+	public $entry;
66
+
67
+	/**
68
+	 * @var \GV\Request The request context.
69
+	 */
70
+	public $request;
71
+
72
+	/**
73
+	 * @var string The template slug to be loaded (like "table", "list")
74
+	 */
75
+	public static $slug;
76
+
77
+	/**
78
+	 * Initializer.
79
+	 *
80
+	 * @param \GV\Field   $field   The field about to be rendered.
81
+	 * @param \GV\View    $view    The view in this context, if applicable.
82
+	 * @param \GV\Source  $source  The source (form) in this context, if applicable.
83
+	 * @param \GV\Entry   $entry   The entry in this context, if applicable.
84
+	 * @param \GV\Request $request The request in this context, if applicable.
85
+	 */
86
+	public function __construct(Field $field, View $view = null, Source $source = null, Entry $entry = null, Request $request = null)
87
+	{
88
+		$this->field = $field;
89
+		$this->view = $view;
90
+		$this->source = $source;
91
+		$this->entry = $entry;
92
+		$this->request = $request;
93
+
94
+		/** Add granular overrides. */
95
+		add_filter($this->filter_prefix.'_get_template_part', $this->_add_id_specific_templates_callback = self::add_id_specific_templates($this), 10, 3);
96
+
97
+		parent::__construct();
98
+	}
99
+
100
+	public function __destruct()
101
+	{
102
+		remove_filter($this->filter_prefix.'_get_template_part', $this->_add_id_specific_templates_callback);
103
+	}
104
+
105
+	/**
106
+	 * Enable granular template overrides based on current post, view, form, field types, etc.
107
+	 *
108
+	 * Why? See https://github.com/gravityview/GravityView/issues/1024
109
+	 *
110
+	 * @param \GV\Field_Template $template The template instance.
111
+	 *
112
+	 * @return callable The callback bound to `get_template_part`. See `\GV\Field_Template::__construct`
113
+	 */
114
+	public static function add_id_specific_templates($template)
115
+	{
116
+		$inputType = null;
117
+		$field_type = null;
118
+		$field_id = null;
119
+		$view_id = null;
120
+		$form_id = null;
121
+		$is_view = $template->request && $template->request->is_view();
122
+
123
+		if ($template->field) {
124
+			$inputType = $template->field->inputType;
125
+			$field_type = $template->field->type;
126
+			$field_id = $template->field->ID;
127
+		}
128
+
129
+		if ($template->view) {
130
+			$view_id = $template->view->ID;
131
+			$form_id = $template->view->form ? $template->view->form->ID : null;
132
+		}
133
+
134
+		$class = get_class($template);
135
+
136
+		/**
137
+		 * Enable granular template overrides based on current post, view, form, field types, etc.
138
+		 *
139
+		 * The hierarchy is as follows:
140
+		 *
141
+		 * - post-[ID of post of page where view is embedded]-view-[View ID]-field-[Field type]-html.php
142
+		 * - post-[ID of post of page where view is embedded]-view-[View ID]-field-[Field inputType]-html.php
143
+		 * - post-[ID of post of page where view is embedded]-view-[View ID]-field-html.php
144
+		 * - post-[ID of post of page where view is embedded]-field-[Field type]-html.php
145
+		 * - post-[ID of post of page where view is embedded]-field-[Field inputType]-html.php
146
+		 * - post-[ID of post of page where view is embedded]-field-html.php
147
+		 * - post-[ID of post of page where view is embedded]-view-[View ID]-field-[Field type].php
148
+		 * - post-[ID of post of page where view is embedded]-view-[View ID]-field-[Field inputType].php
149
+		 * - post-[ID of post of page where view is embedded]-view-[View ID]-field.php
150
+		 * - post-[ID of post of page where view is embedded]-field-[Field type].php
151
+		 * - post-[ID of post of page where view is embedded]-field-[Field inputType].php
152
+		 * - post-[ID of post of page where view is embedded]-field.php
153
+		 * - form-[Form ID]-field-[Field ID]-html.php
154
+		 * - form-[Form ID]-field-[Field ID].php
155
+		 * - form-[Form ID]-field-[Field type]-html.php
156
+		 * - form-[Form ID]-field-[Field inputType]-html.php
157
+		 * - form-[Form ID]-field-[Field type].php
158
+		 * - form-[Form ID]-field-[Field inputType].php
159
+		 * - view-[View ID]-field-[Field type]-html.php
160
+		 * - view-[View ID]-field-[Field inputType]-html.php
161
+		 * - view-[View ID]-field-[Field type].php
162
+		 * - view-[View ID]-field-[Field inputType].php
163
+		 * - field-[Field type]-html.php
164
+		 * - field-[Field inputType]-html.php
165
+		 * - field-[Field type].php
166
+		 * - field-[Field inputType].php
167
+		 * - field-html.php
168
+		 * - field.php
169
+		 *
170
+		 * @see  Gamajo_Template_Loader::get_template_file_names() Where the filter is
171
+		 *
172
+		 * @param array  $templates Existing list of templates.
173
+		 * @param string $slug      Name of the template base, example: `html`, `json`, `xml`
174
+		 * @param string $name      Name of the template part.
175
+		 *
176
+		 * @return array $templates Modified template array, merged with existing $templates values
177
+		 */
178
+		return function ($templates, $slug, $name) use ($class, $inputType, $field_type, $view_id, $is_view, $form_id, $field_id) {
179
+			$specifics = [];
180
+
181
+			list($slug_dir, $slug_name) = $class::split_slug($slug, $name);
182
+
183
+			global $post;
184
+
185
+			if ($is_view && $post) {
186
+				if ($field_type) {
187
+					$specifics[] = sprintf('%spost-%d-view-%d-field-%s-%s.php', $slug_dir, $post->ID, $view_id, $field_type, $slug_name);
188
+					$inputType && $specifics[] = sprintf('%spost-%d-view-%d-field-%s-%s.php', $slug_dir, $post->ID, $view_id, $inputType, $slug_name);
189
+					$specifics[] = sprintf('%spost-%d-view-%d-field-%s.php', $slug_dir, $post->ID, $view_id, $field_type);
190
+					$inputType && $specifics[] = sprintf('%spost-%d-view-%d-field-%s.php', $slug_dir, $post->ID, $view_id, $inputType);
191
+					$specifics[] = sprintf('%spost-%d-field-%s-%s.php', $slug_dir, $post->ID, $field_type, $slug_name);
192
+					$inputType && $specifics[] = sprintf('%spost-%d-field-%s-%s.php', $slug_dir, $post->ID, $inputType, $slug_name);
193
+					$specifics[] = sprintf('%spost-%d-field-%s.php', $slug_dir, $post->ID, $field_type);
194
+					$inputType && $specifics[] = sprintf('%spost-%d-field-%s.php', $slug_dir, $post->ID, $inputType);
195
+				}
196
+
197
+				$specifics[] = sprintf('%spost-%d-view-%d-field-%s.php', $slug_dir, $post->ID, $view_id, $slug_name);
198
+				$specifics[] = sprintf('%spost-%d-view-%d-field.php', $slug_dir, $post->ID, $view_id);
199
+				$specifics[] = sprintf('%spost-%d-field-%s.php', $slug_dir, $post->ID, $slug_name);
200
+				$specifics[] = sprintf('%spost-%d-field.php', $slug_dir, $post->ID);
201
+			}
202
+
203
+			/** Field-specific */
204
+			if ($field_id && $form_id) {
205
+				if ($field_id) {
206
+					$specifics[] = sprintf('%sform-%d-field-%d-%s.php', $slug_dir, $form_id, $field_id, $slug_name);
207
+					$specifics[] = sprintf('%sform-%d-field-%d.php', $slug_dir, $form_id, $field_id);
208
+
209
+					if ($view_id) {
210
+						$specifics[] = sprintf('%sview-%d-field-%d.php', $slug_dir, $view_id, $field_id);
211
+					}
212
+				}
213
+
214
+				if ($field_type) {
215
+					$specifics[] = sprintf('%sform-%d-field-%s-%s.php', $slug_dir, $form_id, $field_type, $slug_name);
216
+					$inputType && $specifics[] = sprintf('%sform-%d-field-%s-%s.php', $slug_dir, $form_id, $inputType, $slug_name);
217
+					$specifics[] = sprintf('%sform-%d-field-%s.php', $slug_dir, $form_id, $field_type);
218
+					$inputType && $specifics[] = sprintf('%sform-%d-field-%s.php', $slug_dir, $form_id, $inputType);
219
+
220
+					$specifics[] = sprintf('%sview-%d-field-%s-%s.php', $slug_dir, $view_id, $field_type, $slug_name);
221
+					$inputType && $specifics[] = sprintf('%sview-%d-field-%s-%s.php', $slug_dir, $view_id, $inputType, $slug_name);
222
+					$specifics[] = sprintf('%sview-%d-field-%s.php', $slug_dir, $view_id, $field_type);
223
+					$inputType && $specifics[] = sprintf('%sview-%d-field-%s.php', $slug_dir, $view_id, $inputType);
224
+
225
+					$specifics[] = sprintf('%sfield-%s-%s.php', $slug_dir, $field_type, $slug_name);
226
+					$inputType && $specifics[] = sprintf('%sfield-%s-%s.php', $slug_dir, $inputType, $slug_name);
227
+					$specifics[] = sprintf('%sfield-%s.php', $slug_dir, $field_type);
228
+					$inputType && $specifics[] = sprintf('%sfield-%s.php', $slug_dir, $inputType);
229
+				}
230
+			}
231
+
232
+			if ($form_id) {
233
+				/** Generic field templates */
234
+				$specifics[] = sprintf('%sview-%d-field-%s.php', $slug_dir, $view_id, $slug_name);
235
+				$specifics[] = sprintf('%sform-%d-field-%s.php', $slug_dir, $form_id, $slug_name);
236
+
237
+				$specifics[] = sprintf('%sview-%d-field.php', $slug_dir, $view_id);
238
+				$specifics[] = sprintf('%sform-%d-field.php', $slug_dir, $form_id);
239
+			}
240
+
241
+			/**
242
+			 * Legacy.
243
+			 * Ignore some types that conflict.
244
+			 */
245
+			if (!in_array($field_type, ['notes'])) {
246
+				$specifics[] = sprintf('%s.php', $field_type);
247
+				$specifics[] = sprintf('fields/%s.php', $field_type);
248
+			}
249
+
250
+			$specifics[] = sprintf('%sfield-%s.php', $slug_dir, $slug_name);
251
+			$specifics[] = sprintf('%sfield.php', $slug_dir);
252
+
253
+			return array_merge($specifics, $templates);
254
+		};
255
+	}
256
+
257
+	/**
258
+	 * Output some HTML.
259
+	 *
260
+	 * @todo Move to \GV\Field_HTML_Template, but call filters here?
261
+	 *
262
+	 * @return void
263
+	 */
264
+	public function render()
265
+	{
266
+		if (!$entry = $this->entry->from_field($this->field)) {
267
+			gravityview()->log->error('Entry is invalid for field. Returning empty.');
268
+
269
+			return;
270
+		}
271
+
272
+		/** Retrieve the value. */
273
+		$display_value = $value = $this->field->get_value($this->view, $this->source, $entry);
274
+
275
+		$source = $this->source;
276
+		$source_backend = $source ? $source::$backend : null;
277
+
278
+		\GV\Mocks\Legacy_Context::load([
279
+			'field' => $this->field,
280
+		]);
281
+
282
+		/** Alter the display value according to Gravity Forms. */
283
+		if (\GV\Source::BACKEND_GRAVITYFORMS === $source_backend && !$this->field instanceof Internal_Field) {
284
+
285
+			/** Prevent any PHP warnings that may be generated. */
286
+			ob_start();
287
+
288
+			$display_value = \GFCommon::get_lead_field_display($this->field->field, $value, $entry['currency'], false, 'html');
289
+
290
+			if ($errors = ob_get_clean()) {
291
+				gravityview()->log->error('Errors when calling GFCommon::get_lead_field_display()', ['data' => $errors]);
292
+			}
293
+
294
+			// `gform_entry_field_value` expects a GF_Field, but $this->field->field can be NULL
295
+			if (!$this->field->field instanceof GF_Field) {
296
+				$gf_field = \GF_Fields::create($this->field->field);
297
+			}
298
+
299
+			/** Call the Gravity Forms field value filter. */
300
+			$display_value = apply_filters('gform_entry_field_value', $display_value, $gf_field, $entry->as_entry(), $this->source->form);
301
+
302
+			unset($gf_field);
303
+
304
+			/** Replace merge tags for admin-only fields. */
305
+			if (!empty($this->field->field->adminOnly)) {
306
+				$display_value = \GravityView_API::replace_variables($display_value, $this->form->form, $entry->as_entry(), false, false);
307
+			}
308
+		}
309
+
310
+		$context = Template_Context::from_template($this, compact('display_value', 'value'));
311
+
312
+		/**
313
+		 * Make various pieces of data available to the template
314
+		 *  under the $gravityview scoped variable.
315
+		 *
316
+		 * @filter `gravityview/template/field/context`
317
+		 *
318
+		 * @param \GV\Template_Context $context The context for this template.
319
+		 *
320
+		 * @since 2.0
321
+		 */
322
+		$this->push_template_data(apply_filters('gravityview/template/field/context', $context), 'gravityview');
323
+
324
+		/** Bake the template. */
325
+		ob_start();
326
+		$this->located_template = $this->get_template_part(static::$slug);
327
+		$output = ob_get_clean();
328
+
329
+		if (empty($output)) {
330
+			/**
331
+			 * @filter `gravityview_empty_value` What to display when a field is empty
332
+			 *
333
+			 * @deprecated Use the `gravityview/field/value/empty` filter instead
334
+			 *
335
+			 * @param string $value (empty string)
336
+			 */
337
+			$output = apply_filters('gravityview_empty_value', $output);
338
+
339
+			/**
340
+			 * @filter `gravityview/field/value/empty` What to display when this field is empty.
341
+			 *
342
+			 * @param string $value The value to display (Default: empty string)
343
+			 * @param \GV\Template_Context The template context this is being called from.
344
+			 */
345
+			$output = apply_filters('gravityview/field/value/empty', $output, Template_Context::from_template($this));
346
+
347
+			$context = Template_Context::from_template($this, compact('display_value', 'value'));
348
+		}
349
+
350
+		gravityview()->log->info('Field template for field #{field_id} loaded: {located_template}', ['field_id' => $this->field->ID, 'located_template' => $this->located_template]);
351
+
352
+		$this->pop_template_data('gravityview');
353
+
354
+		/** A compatibility array that's required by some of the deprecated filters. */
355
+		$field_compat = [
356
+			'form'           => $source_backend == \GV\Source::BACKEND_GRAVITYFORMS ? $this->source->form : ($this->view->form ? $this->view->form->form : null),
357
+			'field_id'       => $this->field->ID,
358
+			'field'          => $this->field->field,
359
+			'field_settings' => $this->field->as_configuration(),
360
+			'value'          => $value,
361
+			'display_value'  => $display_value,
362
+			'format'         => 'html',
363
+			'entry'          => $entry->as_entry(),
364
+			'field_type'     => $this->field->type,
365
+			'field_path'     => $this->located_template,
366
+		];
367
+
368
+		/**
369
+		 * Wrap output in a link, if enabled in the field settings.
370
+		 *
371
+		 * @todo Cleanup
372
+		 *
373
+		 * @param string               $output  HTML value output
374
+		 * @param \GV\Template_Context $context
375
+		 *
376
+		 * @return mixed|string|void
377
+		 */
378
+		$pre_link_compat_callback = function ($output, $context) use ($field_compat) {
379
+			$field = $context->field;
380
+
381
+			/**
382
+			 * @filter `gravityview_field_entry_value_{$field_type}_pre_link` Modify the field value output for a field type before Show As Link setting is applied. Example: `gravityview_field_entry_value_number_pre_link`
383
+			 *
384
+			 * @since 1.16
385
+			 *
386
+			 * @param string $output         HTML value output
387
+			 * @param array  $entry          The GF entry array
388
+			 * @param array  $field_settings Settings for the particular GV field
389
+			 * @param array  $field          Field array, as fetched from GravityView_View::getCurrentField()
390
+			 *
391
+			 * @deprecated Use the `gravityview/field/{$field_type}/output` or `gravityview/field/output` filters instead.
392
+			 */
393
+			$output = apply_filters("gravityview_field_entry_value_{$field->type}_pre_link", $output, $context->entry->as_entry(), $field->as_configuration(), $field_compat);
394
+
395
+			$output = apply_filters('gravityview_field_entry_value_pre_link', $output, $context->entry->as_entry(), $field->as_configuration(), $field_compat);
396
+
397
+			/**
398
+			 * Link to the single entry by wrapping the output in an anchor tag.
399
+			 *
400
+			 * Fields can override this by modifying the field data variable inside the field. See /templates/fields/post_image.php for an example.
401
+			 */
402
+			if (!empty($field->show_as_link) && !\gv_empty($output, false, false)) {
403
+				$link_atts = empty($field->new_window) ? [] : ['target' => '_blank'];
404
+
405
+				$permalink = $context->entry->get_permalink($context->view, $context->request);
406
+				$output = \gravityview_get_link($permalink, $output, $link_atts);
407
+
408
+				/**
409
+				 * @filter `gravityview_field_entry_link` Modify the link HTML
410
+				 *
411
+				 * @param string $link           HTML output of the link
412
+				 * @param string $href           URL of the link
413
+				 * @param array  $entry          The GF entry array
414
+				 * @param array  $field_settings Settings for the particular GV field
415
+				 *
416
+				 * @deprecated Use `gravityview/template/field/entry_link`
417
+				 */
418
+				$output = apply_filters('gravityview_field_entry_link', $output, $permalink, $context->entry->as_entry(), $field->as_configuration());
419
+
420
+				/**
421
+				 * @filter `gravityview/template/field/entry_link` Modify the link HTML
422
+				 *
423
+				 * @since 2.0
424
+				 *
425
+				 * @param string               $link    HTML output of the link
426
+				 * @param string               $href    URL of the link
427
+				 * @param \GV\Template_Context $context The context
428
+				 */
429
+				$output = apply_filters('gravityview/template/field/entry_link', $output, $permalink, $context);
430
+			}
431
+
432
+			return $output;
433
+		};
434
+
435
+		// TODO Cleanup
436
+		$post_link_compat_callback = function ($output, $context) use ($field_compat) {
437
+			$field = $context->field;
438
+
439
+			/**
440
+			 * @filter `gravityview_field_entry_value_{$field_type}` Modify the field value output for a field type. Example: `gravityview_field_entry_value_number`
441
+			 *
442
+			 * @since 1.6
443
+			 *
444
+			 * @param string $output         HTML value output
445
+			 * @param array  $entry          The GF entry array
446
+			 * @param array  $field_settings Settings for the particular GV field
447
+			 * @param array  $field          Current field being displayed
448
+			 *
449
+			 * @deprecated Use the `gravityview/field/{$field_type}/output` or `gravityview/field/output` filters instead.
450
+			 */
451
+			$output = apply_filters("gravityview_field_entry_value_{$field->type}", $output, $context->entry->as_entry(), $field->as_configuration(), $field_compat);
452
+
453
+			/**
454
+			 * @filter `gravityview_field_entry_value` Modify the field value output for all field types
455
+			 *
456
+			 * @param string $output         HTML value output
457
+			 * @param array  $entry          The GF entry array
458
+			 * @param array  $field_settings Settings for the particular GV field
459
+			 * @param array  $field_data     {@since 1.6}
460
+			 *
461
+			 * @deprecated Use the `gravityview/field/{$field_type}/output` or `gravityview/field/output` filters instead.
462
+			 */
463
+			$output = apply_filters('gravityview_field_entry_value', $output, $context->entry->as_entry(), $field->as_configuration(), $field_compat);
464
+
465
+			/**
466
+			 * @filter `gravityview/template/field/{$field_type}/output` Modify the field output for a field type.
467
+			 *
468
+			 * @since 2.0
469
+			 *
470
+			 * @param string $output The current output.
471
+			 * @param \GV\Template_Context The template context this is being called from.
472
+			 */
473
+			return apply_filters("gravityview/template/field/{$field->type}/output", $output, $context);
474
+		};
475
+
476
+		/**
477
+		 * Okay, what's this whole pre/post_link compat deal, huh?
478
+		 *
479
+		 * Well, the `gravityview_field_entry_value_{$field_type}_pre_link` filter
480
+		 *  is expected to be applied before the value is turned into an entry link.
481
+		 *
482
+		 * And then `gravityview_field_entry_value_{$field_type}` and `gravityview_field_entry_value`
483
+		 *  are called afterwards.
484
+		 *
485
+		 * So we're going to use filter priorities to make sure this happens inline with
486
+		 *  our new filters, in the correct sequence. Pre-link called with priority 5 and
487
+		 *  post-link called with priority 9. Then everything else.
488
+		 *
489
+		 * If a new code wants to alter the value before it is hyperlinked (hyperlinkified?),
490
+		 *  it should hook into a priority between -inf. and 8. Afterwards: 10 to +inf.
491
+		 */
492
+		add_filter('gravityview/template/field/output', $pre_link_compat_callback, 5, 2);
493
+		add_filter('gravityview/template/field/output', $post_link_compat_callback, 9, 2);
494
+
495
+		/**
496
+		 * @filter `gravityview/template/field/output` Modify the field output for a field.
497
+		 *
498
+		 * @since 2.0
499
+		 *
500
+		 * @param string $output The current output.
501
+		 * @param \GV\Template_Context The template this is being called from.
502
+		 */
503
+		echo apply_filters('gravityview/template/field/output', $output, $context);
504
+
505
+		remove_filter('gravityview/template/field/output', $pre_link_compat_callback, 5);
506
+		remove_filter('gravityview/template/field/output', $post_link_compat_callback, 9);
507
+	}
508 508
 }
509 509
 
510 510
 /** Load implementations. */
Please login to merge, or discard this patch.
Spacing   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 namespace GV;
4 4
 
5 5
 /** If this file is called directly, abort. */
6
-if (!defined('GRAVITYVIEW_DIR')) {
6
+if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
7 7
     exit();
8 8
 }
9 9
 
@@ -12,8 +12,8 @@  discard block
 block discarded – undo
12 12
  *
13 13
  * @see https://github.com/GaryJones/Gamajo-Template-Loader
14 14
  */
15
-if (!class_exists('\GV\Gamajo_Template_Loader')) {
16
-    require gravityview()->plugin->dir('future/lib/class-gamajo-template-loader.php');
15
+if ( ! class_exists( '\GV\Gamajo_Template_Loader' ) ) {
16
+    require gravityview()->plugin->dir( 'future/lib/class-gamajo-template-loader.php' );
17 17
 }
18 18
 
19 19
 /**
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
      * @param \GV\Entry   $entry   The entry in this context, if applicable.
84 84
      * @param \GV\Request $request The request in this context, if applicable.
85 85
      */
86
-    public function __construct(Field $field, View $view = null, Source $source = null, Entry $entry = null, Request $request = null)
86
+    public function __construct( Field $field, View $view = null, Source $source = null, Entry $entry = null, Request $request = null )
87 87
     {
88 88
         $this->field = $field;
89 89
         $this->view = $view;
@@ -92,14 +92,14 @@  discard block
 block discarded – undo
92 92
         $this->request = $request;
93 93
 
94 94
         /** Add granular overrides. */
95
-        add_filter($this->filter_prefix.'_get_template_part', $this->_add_id_specific_templates_callback = self::add_id_specific_templates($this), 10, 3);
95
+        add_filter( $this->filter_prefix . '_get_template_part', $this->_add_id_specific_templates_callback = self::add_id_specific_templates( $this ), 10, 3 );
96 96
 
97 97
         parent::__construct();
98 98
     }
99 99
 
100 100
     public function __destruct()
101 101
     {
102
-        remove_filter($this->filter_prefix.'_get_template_part', $this->_add_id_specific_templates_callback);
102
+        remove_filter( $this->filter_prefix . '_get_template_part', $this->_add_id_specific_templates_callback );
103 103
     }
104 104
 
105 105
     /**
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
      *
112 112
      * @return callable The callback bound to `get_template_part`. See `\GV\Field_Template::__construct`
113 113
      */
114
-    public static function add_id_specific_templates($template)
114
+    public static function add_id_specific_templates( $template )
115 115
     {
116 116
         $inputType = null;
117 117
         $field_type = null;
@@ -120,18 +120,18 @@  discard block
 block discarded – undo
120 120
         $form_id = null;
121 121
         $is_view = $template->request && $template->request->is_view();
122 122
 
123
-        if ($template->field) {
123
+        if ( $template->field ) {
124 124
             $inputType = $template->field->inputType;
125 125
             $field_type = $template->field->type;
126 126
             $field_id = $template->field->ID;
127 127
         }
128 128
 
129
-        if ($template->view) {
129
+        if ( $template->view ) {
130 130
             $view_id = $template->view->ID;
131 131
             $form_id = $template->view->form ? $template->view->form->ID : null;
132 132
         }
133 133
 
134
-        $class = get_class($template);
134
+        $class = get_class( $template );
135 135
 
136 136
         /**
137 137
          * Enable granular template overrides based on current post, view, form, field types, etc.
@@ -175,82 +175,82 @@  discard block
 block discarded – undo
175 175
          *
176 176
          * @return array $templates Modified template array, merged with existing $templates values
177 177
          */
178
-        return function ($templates, $slug, $name) use ($class, $inputType, $field_type, $view_id, $is_view, $form_id, $field_id) {
179
-            $specifics = [];
178
+        return function( $templates, $slug, $name ) use ( $class, $inputType, $field_type, $view_id, $is_view, $form_id, $field_id ) {
179
+            $specifics = [ ];
180 180
 
181
-            list($slug_dir, $slug_name) = $class::split_slug($slug, $name);
181
+            list( $slug_dir, $slug_name ) = $class::split_slug( $slug, $name );
182 182
 
183 183
             global $post;
184 184
 
185
-            if ($is_view && $post) {
186
-                if ($field_type) {
187
-                    $specifics[] = sprintf('%spost-%d-view-%d-field-%s-%s.php', $slug_dir, $post->ID, $view_id, $field_type, $slug_name);
188
-                    $inputType && $specifics[] = sprintf('%spost-%d-view-%d-field-%s-%s.php', $slug_dir, $post->ID, $view_id, $inputType, $slug_name);
189
-                    $specifics[] = sprintf('%spost-%d-view-%d-field-%s.php', $slug_dir, $post->ID, $view_id, $field_type);
190
-                    $inputType && $specifics[] = sprintf('%spost-%d-view-%d-field-%s.php', $slug_dir, $post->ID, $view_id, $inputType);
191
-                    $specifics[] = sprintf('%spost-%d-field-%s-%s.php', $slug_dir, $post->ID, $field_type, $slug_name);
192
-                    $inputType && $specifics[] = sprintf('%spost-%d-field-%s-%s.php', $slug_dir, $post->ID, $inputType, $slug_name);
193
-                    $specifics[] = sprintf('%spost-%d-field-%s.php', $slug_dir, $post->ID, $field_type);
194
-                    $inputType && $specifics[] = sprintf('%spost-%d-field-%s.php', $slug_dir, $post->ID, $inputType);
185
+            if ( $is_view && $post ) {
186
+                if ( $field_type ) {
187
+                    $specifics[ ] = sprintf( '%spost-%d-view-%d-field-%s-%s.php', $slug_dir, $post->ID, $view_id, $field_type, $slug_name );
188
+                    $inputType && $specifics[ ] = sprintf( '%spost-%d-view-%d-field-%s-%s.php', $slug_dir, $post->ID, $view_id, $inputType, $slug_name );
189
+                    $specifics[ ] = sprintf( '%spost-%d-view-%d-field-%s.php', $slug_dir, $post->ID, $view_id, $field_type );
190
+                    $inputType && $specifics[ ] = sprintf( '%spost-%d-view-%d-field-%s.php', $slug_dir, $post->ID, $view_id, $inputType );
191
+                    $specifics[ ] = sprintf( '%spost-%d-field-%s-%s.php', $slug_dir, $post->ID, $field_type, $slug_name );
192
+                    $inputType && $specifics[ ] = sprintf( '%spost-%d-field-%s-%s.php', $slug_dir, $post->ID, $inputType, $slug_name );
193
+                    $specifics[ ] = sprintf( '%spost-%d-field-%s.php', $slug_dir, $post->ID, $field_type );
194
+                    $inputType && $specifics[ ] = sprintf( '%spost-%d-field-%s.php', $slug_dir, $post->ID, $inputType );
195 195
                 }
196 196
 
197
-                $specifics[] = sprintf('%spost-%d-view-%d-field-%s.php', $slug_dir, $post->ID, $view_id, $slug_name);
198
-                $specifics[] = sprintf('%spost-%d-view-%d-field.php', $slug_dir, $post->ID, $view_id);
199
-                $specifics[] = sprintf('%spost-%d-field-%s.php', $slug_dir, $post->ID, $slug_name);
200
-                $specifics[] = sprintf('%spost-%d-field.php', $slug_dir, $post->ID);
197
+                $specifics[ ] = sprintf( '%spost-%d-view-%d-field-%s.php', $slug_dir, $post->ID, $view_id, $slug_name );
198
+                $specifics[ ] = sprintf( '%spost-%d-view-%d-field.php', $slug_dir, $post->ID, $view_id );
199
+                $specifics[ ] = sprintf( '%spost-%d-field-%s.php', $slug_dir, $post->ID, $slug_name );
200
+                $specifics[ ] = sprintf( '%spost-%d-field.php', $slug_dir, $post->ID );
201 201
             }
202 202
 
203 203
             /** Field-specific */
204
-            if ($field_id && $form_id) {
205
-                if ($field_id) {
206
-                    $specifics[] = sprintf('%sform-%d-field-%d-%s.php', $slug_dir, $form_id, $field_id, $slug_name);
207
-                    $specifics[] = sprintf('%sform-%d-field-%d.php', $slug_dir, $form_id, $field_id);
204
+            if ( $field_id && $form_id ) {
205
+                if ( $field_id ) {
206
+                    $specifics[ ] = sprintf( '%sform-%d-field-%d-%s.php', $slug_dir, $form_id, $field_id, $slug_name );
207
+                    $specifics[ ] = sprintf( '%sform-%d-field-%d.php', $slug_dir, $form_id, $field_id );
208 208
 
209
-                    if ($view_id) {
210
-                        $specifics[] = sprintf('%sview-%d-field-%d.php', $slug_dir, $view_id, $field_id);
209
+                    if ( $view_id ) {
210
+                        $specifics[ ] = sprintf( '%sview-%d-field-%d.php', $slug_dir, $view_id, $field_id );
211 211
                     }
212 212
                 }
213 213
 
214
-                if ($field_type) {
215
-                    $specifics[] = sprintf('%sform-%d-field-%s-%s.php', $slug_dir, $form_id, $field_type, $slug_name);
216
-                    $inputType && $specifics[] = sprintf('%sform-%d-field-%s-%s.php', $slug_dir, $form_id, $inputType, $slug_name);
217
-                    $specifics[] = sprintf('%sform-%d-field-%s.php', $slug_dir, $form_id, $field_type);
218
-                    $inputType && $specifics[] = sprintf('%sform-%d-field-%s.php', $slug_dir, $form_id, $inputType);
219
-
220
-                    $specifics[] = sprintf('%sview-%d-field-%s-%s.php', $slug_dir, $view_id, $field_type, $slug_name);
221
-                    $inputType && $specifics[] = sprintf('%sview-%d-field-%s-%s.php', $slug_dir, $view_id, $inputType, $slug_name);
222
-                    $specifics[] = sprintf('%sview-%d-field-%s.php', $slug_dir, $view_id, $field_type);
223
-                    $inputType && $specifics[] = sprintf('%sview-%d-field-%s.php', $slug_dir, $view_id, $inputType);
224
-
225
-                    $specifics[] = sprintf('%sfield-%s-%s.php', $slug_dir, $field_type, $slug_name);
226
-                    $inputType && $specifics[] = sprintf('%sfield-%s-%s.php', $slug_dir, $inputType, $slug_name);
227
-                    $specifics[] = sprintf('%sfield-%s.php', $slug_dir, $field_type);
228
-                    $inputType && $specifics[] = sprintf('%sfield-%s.php', $slug_dir, $inputType);
214
+                if ( $field_type ) {
215
+                    $specifics[ ] = sprintf( '%sform-%d-field-%s-%s.php', $slug_dir, $form_id, $field_type, $slug_name );
216
+                    $inputType && $specifics[ ] = sprintf( '%sform-%d-field-%s-%s.php', $slug_dir, $form_id, $inputType, $slug_name );
217
+                    $specifics[ ] = sprintf( '%sform-%d-field-%s.php', $slug_dir, $form_id, $field_type );
218
+                    $inputType && $specifics[ ] = sprintf( '%sform-%d-field-%s.php', $slug_dir, $form_id, $inputType );
219
+
220
+                    $specifics[ ] = sprintf( '%sview-%d-field-%s-%s.php', $slug_dir, $view_id, $field_type, $slug_name );
221
+                    $inputType && $specifics[ ] = sprintf( '%sview-%d-field-%s-%s.php', $slug_dir, $view_id, $inputType, $slug_name );
222
+                    $specifics[ ] = sprintf( '%sview-%d-field-%s.php', $slug_dir, $view_id, $field_type );
223
+                    $inputType && $specifics[ ] = sprintf( '%sview-%d-field-%s.php', $slug_dir, $view_id, $inputType );
224
+
225
+                    $specifics[ ] = sprintf( '%sfield-%s-%s.php', $slug_dir, $field_type, $slug_name );
226
+                    $inputType && $specifics[ ] = sprintf( '%sfield-%s-%s.php', $slug_dir, $inputType, $slug_name );
227
+                    $specifics[ ] = sprintf( '%sfield-%s.php', $slug_dir, $field_type );
228
+                    $inputType && $specifics[ ] = sprintf( '%sfield-%s.php', $slug_dir, $inputType );
229 229
                 }
230 230
             }
231 231
 
232
-            if ($form_id) {
232
+            if ( $form_id ) {
233 233
                 /** Generic field templates */
234
-                $specifics[] = sprintf('%sview-%d-field-%s.php', $slug_dir, $view_id, $slug_name);
235
-                $specifics[] = sprintf('%sform-%d-field-%s.php', $slug_dir, $form_id, $slug_name);
234
+                $specifics[ ] = sprintf( '%sview-%d-field-%s.php', $slug_dir, $view_id, $slug_name );
235
+                $specifics[ ] = sprintf( '%sform-%d-field-%s.php', $slug_dir, $form_id, $slug_name );
236 236
 
237
-                $specifics[] = sprintf('%sview-%d-field.php', $slug_dir, $view_id);
238
-                $specifics[] = sprintf('%sform-%d-field.php', $slug_dir, $form_id);
237
+                $specifics[ ] = sprintf( '%sview-%d-field.php', $slug_dir, $view_id );
238
+                $specifics[ ] = sprintf( '%sform-%d-field.php', $slug_dir, $form_id );
239 239
             }
240 240
 
241 241
             /**
242 242
              * Legacy.
243 243
              * Ignore some types that conflict.
244 244
              */
245
-            if (!in_array($field_type, ['notes'])) {
246
-                $specifics[] = sprintf('%s.php', $field_type);
247
-                $specifics[] = sprintf('fields/%s.php', $field_type);
245
+            if ( ! in_array( $field_type, [ 'notes' ] ) ) {
246
+                $specifics[ ] = sprintf( '%s.php', $field_type );
247
+                $specifics[ ] = sprintf( 'fields/%s.php', $field_type );
248 248
             }
249 249
 
250
-            $specifics[] = sprintf('%sfield-%s.php', $slug_dir, $slug_name);
251
-            $specifics[] = sprintf('%sfield.php', $slug_dir);
250
+            $specifics[ ] = sprintf( '%sfield-%s.php', $slug_dir, $slug_name );
251
+            $specifics[ ] = sprintf( '%sfield.php', $slug_dir );
252 252
 
253
-            return array_merge($specifics, $templates);
253
+            return array_merge( $specifics, $templates );
254 254
         };
255 255
     }
256 256
 
@@ -263,51 +263,51 @@  discard block
 block discarded – undo
263 263
      */
264 264
     public function render()
265 265
     {
266
-        if (!$entry = $this->entry->from_field($this->field)) {
267
-            gravityview()->log->error('Entry is invalid for field. Returning empty.');
266
+        if ( ! $entry = $this->entry->from_field( $this->field ) ) {
267
+            gravityview()->log->error( 'Entry is invalid for field. Returning empty.' );
268 268
 
269 269
             return;
270 270
         }
271 271
 
272 272
         /** Retrieve the value. */
273
-        $display_value = $value = $this->field->get_value($this->view, $this->source, $entry);
273
+        $display_value = $value = $this->field->get_value( $this->view, $this->source, $entry );
274 274
 
275 275
         $source = $this->source;
276 276
         $source_backend = $source ? $source::$backend : null;
277 277
 
278
-        \GV\Mocks\Legacy_Context::load([
278
+        \GV\Mocks\Legacy_Context::load( [
279 279
             'field' => $this->field,
280
-        ]);
280
+        ] );
281 281
 
282 282
         /** Alter the display value according to Gravity Forms. */
283
-        if (\GV\Source::BACKEND_GRAVITYFORMS === $source_backend && !$this->field instanceof Internal_Field) {
283
+        if ( \GV\Source::BACKEND_GRAVITYFORMS === $source_backend && ! $this->field instanceof Internal_Field ) {
284 284
 
285 285
             /** Prevent any PHP warnings that may be generated. */
286 286
             ob_start();
287 287
 
288
-            $display_value = \GFCommon::get_lead_field_display($this->field->field, $value, $entry['currency'], false, 'html');
288
+            $display_value = \GFCommon::get_lead_field_display( $this->field->field, $value, $entry[ 'currency' ], false, 'html' );
289 289
 
290
-            if ($errors = ob_get_clean()) {
291
-                gravityview()->log->error('Errors when calling GFCommon::get_lead_field_display()', ['data' => $errors]);
290
+            if ( $errors = ob_get_clean() ) {
291
+                gravityview()->log->error( 'Errors when calling GFCommon::get_lead_field_display()', [ 'data' => $errors ] );
292 292
             }
293 293
 
294 294
             // `gform_entry_field_value` expects a GF_Field, but $this->field->field can be NULL
295
-            if (!$this->field->field instanceof GF_Field) {
296
-                $gf_field = \GF_Fields::create($this->field->field);
295
+            if ( ! $this->field->field instanceof GF_Field ) {
296
+                $gf_field = \GF_Fields::create( $this->field->field );
297 297
             }
298 298
 
299 299
             /** Call the Gravity Forms field value filter. */
300
-            $display_value = apply_filters('gform_entry_field_value', $display_value, $gf_field, $entry->as_entry(), $this->source->form);
300
+            $display_value = apply_filters( 'gform_entry_field_value', $display_value, $gf_field, $entry->as_entry(), $this->source->form );
301 301
 
302
-            unset($gf_field);
302
+            unset( $gf_field );
303 303
 
304 304
             /** Replace merge tags for admin-only fields. */
305
-            if (!empty($this->field->field->adminOnly)) {
306
-                $display_value = \GravityView_API::replace_variables($display_value, $this->form->form, $entry->as_entry(), false, false);
305
+            if ( ! empty( $this->field->field->adminOnly ) ) {
306
+                $display_value = \GravityView_API::replace_variables( $display_value, $this->form->form, $entry->as_entry(), false, false );
307 307
             }
308 308
         }
309 309
 
310
-        $context = Template_Context::from_template($this, compact('display_value', 'value'));
310
+        $context = Template_Context::from_template( $this, compact( 'display_value', 'value' ) );
311 311
 
312 312
         /**
313 313
          * Make various pieces of data available to the template
@@ -319,14 +319,14 @@  discard block
 block discarded – undo
319 319
          *
320 320
          * @since 2.0
321 321
          */
322
-        $this->push_template_data(apply_filters('gravityview/template/field/context', $context), 'gravityview');
322
+        $this->push_template_data( apply_filters( 'gravityview/template/field/context', $context ), 'gravityview' );
323 323
 
324 324
         /** Bake the template. */
325 325
         ob_start();
326
-        $this->located_template = $this->get_template_part(static::$slug);
326
+        $this->located_template = $this->get_template_part( static::$slug );
327 327
         $output = ob_get_clean();
328 328
 
329
-        if (empty($output)) {
329
+        if ( empty( $output ) ) {
330 330
             /**
331 331
              * @filter `gravityview_empty_value` What to display when a field is empty
332 332
              *
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
              *
335 335
              * @param string $value (empty string)
336 336
              */
337
-            $output = apply_filters('gravityview_empty_value', $output);
337
+            $output = apply_filters( 'gravityview_empty_value', $output );
338 338
 
339 339
             /**
340 340
              * @filter `gravityview/field/value/empty` What to display when this field is empty.
@@ -342,18 +342,18 @@  discard block
 block discarded – undo
342 342
              * @param string $value The value to display (Default: empty string)
343 343
              * @param \GV\Template_Context The template context this is being called from.
344 344
              */
345
-            $output = apply_filters('gravityview/field/value/empty', $output, Template_Context::from_template($this));
345
+            $output = apply_filters( 'gravityview/field/value/empty', $output, Template_Context::from_template( $this ) );
346 346
 
347
-            $context = Template_Context::from_template($this, compact('display_value', 'value'));
347
+            $context = Template_Context::from_template( $this, compact( 'display_value', 'value' ) );
348 348
         }
349 349
 
350
-        gravityview()->log->info('Field template for field #{field_id} loaded: {located_template}', ['field_id' => $this->field->ID, 'located_template' => $this->located_template]);
350
+        gravityview()->log->info( 'Field template for field #{field_id} loaded: {located_template}', [ 'field_id' => $this->field->ID, 'located_template' => $this->located_template ] );
351 351
 
352
-        $this->pop_template_data('gravityview');
352
+        $this->pop_template_data( 'gravityview' );
353 353
 
354 354
         /** A compatibility array that's required by some of the deprecated filters. */
355 355
         $field_compat = [
356
-            'form'           => $source_backend == \GV\Source::BACKEND_GRAVITYFORMS ? $this->source->form : ($this->view->form ? $this->view->form->form : null),
356
+            'form'           => $source_backend == \GV\Source::BACKEND_GRAVITYFORMS ? $this->source->form : ( $this->view->form ? $this->view->form->form : null ),
357 357
             'field_id'       => $this->field->ID,
358 358
             'field'          => $this->field->field,
359 359
             'field_settings' => $this->field->as_configuration(),
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
          *
376 376
          * @return mixed|string|void
377 377
          */
378
-        $pre_link_compat_callback = function ($output, $context) use ($field_compat) {
378
+        $pre_link_compat_callback = function( $output, $context ) use ( $field_compat ) {
379 379
             $field = $context->field;
380 380
 
381 381
             /**
@@ -390,20 +390,20 @@  discard block
 block discarded – undo
390 390
              *
391 391
              * @deprecated Use the `gravityview/field/{$field_type}/output` or `gravityview/field/output` filters instead.
392 392
              */
393
-            $output = apply_filters("gravityview_field_entry_value_{$field->type}_pre_link", $output, $context->entry->as_entry(), $field->as_configuration(), $field_compat);
393
+            $output = apply_filters( "gravityview_field_entry_value_{$field->type}_pre_link", $output, $context->entry->as_entry(), $field->as_configuration(), $field_compat );
394 394
 
395
-            $output = apply_filters('gravityview_field_entry_value_pre_link', $output, $context->entry->as_entry(), $field->as_configuration(), $field_compat);
395
+            $output = apply_filters( 'gravityview_field_entry_value_pre_link', $output, $context->entry->as_entry(), $field->as_configuration(), $field_compat );
396 396
 
397 397
             /**
398 398
              * Link to the single entry by wrapping the output in an anchor tag.
399 399
              *
400 400
              * Fields can override this by modifying the field data variable inside the field. See /templates/fields/post_image.php for an example.
401 401
              */
402
-            if (!empty($field->show_as_link) && !\gv_empty($output, false, false)) {
403
-                $link_atts = empty($field->new_window) ? [] : ['target' => '_blank'];
402
+            if ( ! empty( $field->show_as_link ) && ! \gv_empty( $output, false, false ) ) {
403
+                $link_atts = empty( $field->new_window ) ? [ ] : [ 'target' => '_blank' ];
404 404
 
405
-                $permalink = $context->entry->get_permalink($context->view, $context->request);
406
-                $output = \gravityview_get_link($permalink, $output, $link_atts);
405
+                $permalink = $context->entry->get_permalink( $context->view, $context->request );
406
+                $output = \gravityview_get_link( $permalink, $output, $link_atts );
407 407
 
408 408
                 /**
409 409
                  * @filter `gravityview_field_entry_link` Modify the link HTML
@@ -415,7 +415,7 @@  discard block
 block discarded – undo
415 415
                  *
416 416
                  * @deprecated Use `gravityview/template/field/entry_link`
417 417
                  */
418
-                $output = apply_filters('gravityview_field_entry_link', $output, $permalink, $context->entry->as_entry(), $field->as_configuration());
418
+                $output = apply_filters( 'gravityview_field_entry_link', $output, $permalink, $context->entry->as_entry(), $field->as_configuration() );
419 419
 
420 420
                 /**
421 421
                  * @filter `gravityview/template/field/entry_link` Modify the link HTML
@@ -426,14 +426,14 @@  discard block
 block discarded – undo
426 426
                  * @param string               $href    URL of the link
427 427
                  * @param \GV\Template_Context $context The context
428 428
                  */
429
-                $output = apply_filters('gravityview/template/field/entry_link', $output, $permalink, $context);
429
+                $output = apply_filters( 'gravityview/template/field/entry_link', $output, $permalink, $context );
430 430
             }
431 431
 
432 432
             return $output;
433 433
         };
434 434
 
435 435
         // TODO Cleanup
436
-        $post_link_compat_callback = function ($output, $context) use ($field_compat) {
436
+        $post_link_compat_callback = function( $output, $context ) use ( $field_compat ) {
437 437
             $field = $context->field;
438 438
 
439 439
             /**
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
              *
449 449
              * @deprecated Use the `gravityview/field/{$field_type}/output` or `gravityview/field/output` filters instead.
450 450
              */
451
-            $output = apply_filters("gravityview_field_entry_value_{$field->type}", $output, $context->entry->as_entry(), $field->as_configuration(), $field_compat);
451
+            $output = apply_filters( "gravityview_field_entry_value_{$field->type}", $output, $context->entry->as_entry(), $field->as_configuration(), $field_compat );
452 452
 
453 453
             /**
454 454
              * @filter `gravityview_field_entry_value` Modify the field value output for all field types
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
              *
461 461
              * @deprecated Use the `gravityview/field/{$field_type}/output` or `gravityview/field/output` filters instead.
462 462
              */
463
-            $output = apply_filters('gravityview_field_entry_value', $output, $context->entry->as_entry(), $field->as_configuration(), $field_compat);
463
+            $output = apply_filters( 'gravityview_field_entry_value', $output, $context->entry->as_entry(), $field->as_configuration(), $field_compat );
464 464
 
465 465
             /**
466 466
              * @filter `gravityview/template/field/{$field_type}/output` Modify the field output for a field type.
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
              * @param string $output The current output.
471 471
              * @param \GV\Template_Context The template context this is being called from.
472 472
              */
473
-            return apply_filters("gravityview/template/field/{$field->type}/output", $output, $context);
473
+            return apply_filters( "gravityview/template/field/{$field->type}/output", $output, $context );
474 474
         };
475 475
 
476 476
         /**
@@ -489,8 +489,8 @@  discard block
 block discarded – undo
489 489
          * If a new code wants to alter the value before it is hyperlinked (hyperlinkified?),
490 490
          *  it should hook into a priority between -inf. and 8. Afterwards: 10 to +inf.
491 491
          */
492
-        add_filter('gravityview/template/field/output', $pre_link_compat_callback, 5, 2);
493
-        add_filter('gravityview/template/field/output', $post_link_compat_callback, 9, 2);
492
+        add_filter( 'gravityview/template/field/output', $pre_link_compat_callback, 5, 2 );
493
+        add_filter( 'gravityview/template/field/output', $post_link_compat_callback, 9, 2 );
494 494
 
495 495
         /**
496 496
          * @filter `gravityview/template/field/output` Modify the field output for a field.
@@ -500,13 +500,13 @@  discard block
 block discarded – undo
500 500
          * @param string $output The current output.
501 501
          * @param \GV\Template_Context The template this is being called from.
502 502
          */
503
-        echo apply_filters('gravityview/template/field/output', $output, $context);
503
+        echo apply_filters( 'gravityview/template/field/output', $output, $context );
504 504
 
505
-        remove_filter('gravityview/template/field/output', $pre_link_compat_callback, 5);
506
-        remove_filter('gravityview/template/field/output', $post_link_compat_callback, 9);
505
+        remove_filter( 'gravityview/template/field/output', $pre_link_compat_callback, 5 );
506
+        remove_filter( 'gravityview/template/field/output', $post_link_compat_callback, 9 );
507 507
     }
508 508
 }
509 509
 
510 510
 /** Load implementations. */
511
-require gravityview()->plugin->dir('future/includes/class-gv-template-field-html.php');
512
-require gravityview()->plugin->dir('future/includes/class-gv-template-field-csv.php');
511
+require gravityview()->plugin->dir( 'future/includes/class-gv-template-field-html.php' );
512
+require gravityview()->plugin->dir( 'future/includes/class-gv-template-field-csv.php' );
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -21,8 +21,7 @@  discard block
 block discarded – undo
21 21
  *
22 22
  * Attached to a \GV\Field and used by a \GV\Field_Renderer.
23 23
  */
24
-abstract class Field_Template extends Template
25
-{
24
+abstract class Field_Template extends Template {
26 25
     /**
27 26
      * Prefix for filter names.
28 27
      *
@@ -83,8 +82,7 @@  discard block
 block discarded – undo
83 82
      * @param \GV\Entry   $entry   The entry in this context, if applicable.
84 83
      * @param \GV\Request $request The request in this context, if applicable.
85 84
      */
86
-    public function __construct(Field $field, View $view = null, Source $source = null, Entry $entry = null, Request $request = null)
87
-    {
85
+    public function __construct(Field $field, View $view = null, Source $source = null, Entry $entry = null, Request $request = null) {
88 86
         $this->field = $field;
89 87
         $this->view = $view;
90 88
         $this->source = $source;
@@ -97,8 +95,7 @@  discard block
 block discarded – undo
97 95
         parent::__construct();
98 96
     }
99 97
 
100
-    public function __destruct()
101
-    {
98
+    public function __destruct() {
102 99
         remove_filter($this->filter_prefix.'_get_template_part', $this->_add_id_specific_templates_callback);
103 100
     }
104 101
 
@@ -111,8 +108,7 @@  discard block
 block discarded – undo
111 108
      *
112 109
      * @return callable The callback bound to `get_template_part`. See `\GV\Field_Template::__construct`
113 110
      */
114
-    public static function add_id_specific_templates($template)
115
-    {
111
+    public static function add_id_specific_templates($template) {
116 112
         $inputType = null;
117 113
         $field_type = null;
118 114
         $field_id = null;
@@ -261,8 +257,7 @@  discard block
 block discarded – undo
261 257
      *
262 258
      * @return void
263 259
      */
264
-    public function render()
265
-    {
260
+    public function render() {
266 261
         if (!$entry = $this->entry->from_field($this->field)) {
267 262
             gravityview()->log->error('Entry is invalid for field. Returning empty.');
268 263
 
Please login to merge, or discard this patch.
future/includes/class-gv-collection-view.php 3 patches
Indentation   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 
5 5
 /** If this file is called directly, abort. */
6 6
 if (!defined('GRAVITYVIEW_DIR')) {
7
-    exit();
7
+	exit();
8 8
 }
9 9
 
10 10
 /**
@@ -12,195 +12,195 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class View_Collection extends Collection
14 14
 {
15
-    /**
16
-     * @inheritDoc
17
-     *
18
-     * @return View[]
19
-     */
20
-    public function all()
21
-    {
22
-        return parent::all();
23
-    }
24
-
25
-    /**
26
-     * Add a \GV\View to this collection.
27
-     *
28
-     * @param \GV\View $view The view to add to the internal array.
29
-     *
30
-     * @api
31
-     *
32
-     * @since 2.0
33
-     *
34
-     * @return void
35
-     */
36
-    public function add($view)
37
-    {
38
-        if (!$view instanceof View) {
39
-            gravityview()->log->error('View_Collections can only contain objects of type \GV\View.');
40
-
41
-            return;
42
-        }
43
-
44
-        parent::add($view);
45
-    }
46
-
47
-    /**
48
-     * Get a \GV\View from this list.
49
-     *
50
-     * @param int $view_id The ID of the view to get.
51
-     *
52
-     * @api
53
-     *
54
-     * @since 2.0
55
-     *
56
-     * @return \GV\View|null The \GV\View with the $view_id as the ID, or null if not found.
57
-     */
58
-    public function get($view_id)
59
-    {
60
-        foreach ($this->all() as $view) {
61
-            if ($view->ID == $view_id) {
62
-                return $view;
63
-            }
64
-        }
65
-
66
-        return null;
67
-    }
68
-
69
-    /**
70
-     * Check whether \GV\View with an ID is already here.
71
-     *
72
-     * @param int $view_id The ID of the view to check.
73
-     *
74
-     * @api
75
-     *
76
-     * @since 2.0
77
-     *
78
-     * @return bool Whether it exists or not.
79
-     */
80
-    public function contains($view_id)
81
-    {
82
-        return !is_null($this->get($view_id));
83
-    }
84
-
85
-    /**
86
-     * Get a list of \GV\View objects inside the supplied \WP_Post.
87
-     *
88
-     * The post can be a gravityview post, which is the simplest case.
89
-     * The post can contain gravityview shortcodes as well.
90
-     * The post meta can contain gravityview shortcodes.
91
-     *
92
-     * @param \WP_Post $post The \WP_Post object to look into.
93
-     *
94
-     * @api
95
-     *
96
-     * @since 2.0
97
-     *
98
-     * @return \GV\View_Collection A \GV\View_Collection instance containing the views inside the supplied \WP_Post.
99
-     */
100
-    public static function from_post(\WP_Post $post)
101
-    {
102
-        $views = new self();
103
-
104
-        $post_type = get_post_type($post);
105
-
106
-        if ('gravityview' === $post_type) {
107
-            /** A straight up gravityview post. */
108
-            $views->add(View::from_post($post));
109
-        } else {
110
-            $views->merge(self::from_content($post->post_content));
111
-
112
-            /**
113
-             * @filter `gravityview/view_collection/from_post/meta_keys` Define meta keys to parse to check for GravityView shortcode content.
114
-             *
115
-             * This is useful when using themes that store content that may contain shortcodes in custom post meta.
116
-             *
117
-             * @since 2.0
118
-             * @since 2.0.7 Added $views parameter, passed by reference
119
-             *
120
-             * @param array               $meta_keys Array of key values to check. If empty, do not check. Default: empty array
121
-             * @param \WP_Post            $post      The post that is being checked
122
-             * @param \GV\View_Collection $views     The current View Collection object, passed as reference
123
-             */
124
-            $meta_keys = apply_filters_ref_array('gravityview/view_collection/from_post/meta_keys', [[], $post, &$views]);
125
-
126
-            /**
127
-             * @filter `gravityview/data/parse/meta_keys`
128
-             *
129
-             * @deprecated
130
-             * @see The `gravityview/view_collection/from_post/meta_keys` filter.
131
-             */
132
-            $meta_keys = (array) apply_filters_deprecated('gravityview/data/parse/meta_keys', [$meta_keys, $post->ID], '2.0.7', 'gravityview/view_collection/from_post/meta_keys');
133
-
134
-            /** What about inside post meta values? */
135
-            foreach ($meta_keys as $meta_key) {
136
-                $views = self::merge_deep($views, $post->{$meta_key});
137
-            }
138
-        }
139
-
140
-        return $views;
141
-    }
142
-
143
-    /**
144
-     * Process meta values when stored singular (string) or multiple (array). Supports nested arrays and JSON strings.
145
-     *
146
-     * @since 2.1
147
-     *
148
-     * @param \GV\View_Collection $views      Existing View Collection to merge with
149
-     * @param string|array        $meta_value Value to parse. Normally the value of $post->{$meta_key}.
150
-     *
151
-     * @return \GV\View_Collection $views View Collection containing any additional Views found
152
-     */
153
-    private static function merge_deep($views, $meta_value)
154
-    {
155
-        $meta_value = gv_maybe_json_decode($meta_value, true);
156
-
157
-        if (is_array($meta_value)) {
158
-            foreach ($meta_value as $index => $item) {
159
-                $meta_value[$index] = self::merge_deep($views, $item);
160
-            }
161
-        }
162
-
163
-        if (is_string($meta_value)) {
164
-            $views->merge(self::from_content($meta_value));
165
-        }
166
-
167
-        return $views;
168
-    }
169
-
170
-    /**
171
-     * Get a list of detected \GV\View objects inside the supplied content.
172
-     *
173
-     * The content can have a shortcode, this is the simplest case.
174
-     *
175
-     * @param string $content The content to look into.
176
-     *
177
-     * @api
178
-     *
179
-     * @since 2.0
180
-     *
181
-     * @return \GV\View_Collection A \GV\View_Collection instance containing the views inside the supplied \WP_Post.
182
-     */
183
-    public static function from_content($content)
184
-    {
185
-        $views = new self();
186
-
187
-        /** Let's find us some [gravityview] shortcodes perhaps. */
188
-        foreach (Shortcode::parse($content) as $shortcode) {
189
-            if ($shortcode->name != 'gravityview' || empty($shortcode->atts['id'])) {
190
-                continue;
191
-            }
192
-
193
-            if (is_numeric($shortcode->atts['id'])) {
194
-                $view = View::by_id($shortcode->atts['id']);
195
-                if (!$view) {
196
-                    continue;
197
-                }
198
-
199
-                $view->settings->update($shortcode->atts);
200
-                $views->add($view);
201
-            }
202
-        }
203
-
204
-        return $views;
205
-    }
15
+	/**
16
+	 * @inheritDoc
17
+	 *
18
+	 * @return View[]
19
+	 */
20
+	public function all()
21
+	{
22
+		return parent::all();
23
+	}
24
+
25
+	/**
26
+	 * Add a \GV\View to this collection.
27
+	 *
28
+	 * @param \GV\View $view The view to add to the internal array.
29
+	 *
30
+	 * @api
31
+	 *
32
+	 * @since 2.0
33
+	 *
34
+	 * @return void
35
+	 */
36
+	public function add($view)
37
+	{
38
+		if (!$view instanceof View) {
39
+			gravityview()->log->error('View_Collections can only contain objects of type \GV\View.');
40
+
41
+			return;
42
+		}
43
+
44
+		parent::add($view);
45
+	}
46
+
47
+	/**
48
+	 * Get a \GV\View from this list.
49
+	 *
50
+	 * @param int $view_id The ID of the view to get.
51
+	 *
52
+	 * @api
53
+	 *
54
+	 * @since 2.0
55
+	 *
56
+	 * @return \GV\View|null The \GV\View with the $view_id as the ID, or null if not found.
57
+	 */
58
+	public function get($view_id)
59
+	{
60
+		foreach ($this->all() as $view) {
61
+			if ($view->ID == $view_id) {
62
+				return $view;
63
+			}
64
+		}
65
+
66
+		return null;
67
+	}
68
+
69
+	/**
70
+	 * Check whether \GV\View with an ID is already here.
71
+	 *
72
+	 * @param int $view_id The ID of the view to check.
73
+	 *
74
+	 * @api
75
+	 *
76
+	 * @since 2.0
77
+	 *
78
+	 * @return bool Whether it exists or not.
79
+	 */
80
+	public function contains($view_id)
81
+	{
82
+		return !is_null($this->get($view_id));
83
+	}
84
+
85
+	/**
86
+	 * Get a list of \GV\View objects inside the supplied \WP_Post.
87
+	 *
88
+	 * The post can be a gravityview post, which is the simplest case.
89
+	 * The post can contain gravityview shortcodes as well.
90
+	 * The post meta can contain gravityview shortcodes.
91
+	 *
92
+	 * @param \WP_Post $post The \WP_Post object to look into.
93
+	 *
94
+	 * @api
95
+	 *
96
+	 * @since 2.0
97
+	 *
98
+	 * @return \GV\View_Collection A \GV\View_Collection instance containing the views inside the supplied \WP_Post.
99
+	 */
100
+	public static function from_post(\WP_Post $post)
101
+	{
102
+		$views = new self();
103
+
104
+		$post_type = get_post_type($post);
105
+
106
+		if ('gravityview' === $post_type) {
107
+			/** A straight up gravityview post. */
108
+			$views->add(View::from_post($post));
109
+		} else {
110
+			$views->merge(self::from_content($post->post_content));
111
+
112
+			/**
113
+			 * @filter `gravityview/view_collection/from_post/meta_keys` Define meta keys to parse to check for GravityView shortcode content.
114
+			 *
115
+			 * This is useful when using themes that store content that may contain shortcodes in custom post meta.
116
+			 *
117
+			 * @since 2.0
118
+			 * @since 2.0.7 Added $views parameter, passed by reference
119
+			 *
120
+			 * @param array               $meta_keys Array of key values to check. If empty, do not check. Default: empty array
121
+			 * @param \WP_Post            $post      The post that is being checked
122
+			 * @param \GV\View_Collection $views     The current View Collection object, passed as reference
123
+			 */
124
+			$meta_keys = apply_filters_ref_array('gravityview/view_collection/from_post/meta_keys', [[], $post, &$views]);
125
+
126
+			/**
127
+			 * @filter `gravityview/data/parse/meta_keys`
128
+			 *
129
+			 * @deprecated
130
+			 * @see The `gravityview/view_collection/from_post/meta_keys` filter.
131
+			 */
132
+			$meta_keys = (array) apply_filters_deprecated('gravityview/data/parse/meta_keys', [$meta_keys, $post->ID], '2.0.7', 'gravityview/view_collection/from_post/meta_keys');
133
+
134
+			/** What about inside post meta values? */
135
+			foreach ($meta_keys as $meta_key) {
136
+				$views = self::merge_deep($views, $post->{$meta_key});
137
+			}
138
+		}
139
+
140
+		return $views;
141
+	}
142
+
143
+	/**
144
+	 * Process meta values when stored singular (string) or multiple (array). Supports nested arrays and JSON strings.
145
+	 *
146
+	 * @since 2.1
147
+	 *
148
+	 * @param \GV\View_Collection $views      Existing View Collection to merge with
149
+	 * @param string|array        $meta_value Value to parse. Normally the value of $post->{$meta_key}.
150
+	 *
151
+	 * @return \GV\View_Collection $views View Collection containing any additional Views found
152
+	 */
153
+	private static function merge_deep($views, $meta_value)
154
+	{
155
+		$meta_value = gv_maybe_json_decode($meta_value, true);
156
+
157
+		if (is_array($meta_value)) {
158
+			foreach ($meta_value as $index => $item) {
159
+				$meta_value[$index] = self::merge_deep($views, $item);
160
+			}
161
+		}
162
+
163
+		if (is_string($meta_value)) {
164
+			$views->merge(self::from_content($meta_value));
165
+		}
166
+
167
+		return $views;
168
+	}
169
+
170
+	/**
171
+	 * Get a list of detected \GV\View objects inside the supplied content.
172
+	 *
173
+	 * The content can have a shortcode, this is the simplest case.
174
+	 *
175
+	 * @param string $content The content to look into.
176
+	 *
177
+	 * @api
178
+	 *
179
+	 * @since 2.0
180
+	 *
181
+	 * @return \GV\View_Collection A \GV\View_Collection instance containing the views inside the supplied \WP_Post.
182
+	 */
183
+	public static function from_content($content)
184
+	{
185
+		$views = new self();
186
+
187
+		/** Let's find us some [gravityview] shortcodes perhaps. */
188
+		foreach (Shortcode::parse($content) as $shortcode) {
189
+			if ($shortcode->name != 'gravityview' || empty($shortcode->atts['id'])) {
190
+				continue;
191
+			}
192
+
193
+			if (is_numeric($shortcode->atts['id'])) {
194
+				$view = View::by_id($shortcode->atts['id']);
195
+				if (!$view) {
196
+					continue;
197
+				}
198
+
199
+				$view->settings->update($shortcode->atts);
200
+				$views->add($view);
201
+			}
202
+		}
203
+
204
+		return $views;
205
+	}
206 206
 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 namespace GV;
4 4
 
5 5
 /** If this file is called directly, abort. */
6
-if (!defined('GRAVITYVIEW_DIR')) {
6
+if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
7 7
     exit();
8 8
 }
9 9
 
@@ -33,15 +33,15 @@  discard block
 block discarded – undo
33 33
      *
34 34
      * @return void
35 35
      */
36
-    public function add($view)
36
+    public function add( $view )
37 37
     {
38
-        if (!$view instanceof View) {
39
-            gravityview()->log->error('View_Collections can only contain objects of type \GV\View.');
38
+        if ( ! $view instanceof View ) {
39
+            gravityview()->log->error( 'View_Collections can only contain objects of type \GV\View.' );
40 40
 
41 41
             return;
42 42
         }
43 43
 
44
-        parent::add($view);
44
+        parent::add( $view );
45 45
     }
46 46
 
47 47
     /**
@@ -55,10 +55,10 @@  discard block
 block discarded – undo
55 55
      *
56 56
      * @return \GV\View|null The \GV\View with the $view_id as the ID, or null if not found.
57 57
      */
58
-    public function get($view_id)
58
+    public function get( $view_id )
59 59
     {
60
-        foreach ($this->all() as $view) {
61
-            if ($view->ID == $view_id) {
60
+        foreach ( $this->all() as $view ) {
61
+            if ( $view->ID == $view_id ) {
62 62
                 return $view;
63 63
             }
64 64
         }
@@ -77,9 +77,9 @@  discard block
 block discarded – undo
77 77
      *
78 78
      * @return bool Whether it exists or not.
79 79
      */
80
-    public function contains($view_id)
80
+    public function contains( $view_id )
81 81
     {
82
-        return !is_null($this->get($view_id));
82
+        return ! is_null( $this->get( $view_id ) );
83 83
     }
84 84
 
85 85
     /**
@@ -97,17 +97,17 @@  discard block
 block discarded – undo
97 97
      *
98 98
      * @return \GV\View_Collection A \GV\View_Collection instance containing the views inside the supplied \WP_Post.
99 99
      */
100
-    public static function from_post(\WP_Post $post)
100
+    public static function from_post( \WP_Post $post )
101 101
     {
102 102
         $views = new self();
103 103
 
104
-        $post_type = get_post_type($post);
104
+        $post_type = get_post_type( $post );
105 105
 
106
-        if ('gravityview' === $post_type) {
106
+        if ( 'gravityview' === $post_type ) {
107 107
             /** A straight up gravityview post. */
108
-            $views->add(View::from_post($post));
108
+            $views->add( View::from_post( $post ) );
109 109
         } else {
110
-            $views->merge(self::from_content($post->post_content));
110
+            $views->merge( self::from_content( $post->post_content ) );
111 111
 
112 112
             /**
113 113
              * @filter `gravityview/view_collection/from_post/meta_keys` Define meta keys to parse to check for GravityView shortcode content.
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
              * @param \WP_Post            $post      The post that is being checked
122 122
              * @param \GV\View_Collection $views     The current View Collection object, passed as reference
123 123
              */
124
-            $meta_keys = apply_filters_ref_array('gravityview/view_collection/from_post/meta_keys', [[], $post, &$views]);
124
+            $meta_keys = apply_filters_ref_array( 'gravityview/view_collection/from_post/meta_keys', [ [ ], $post, &$views ] );
125 125
 
126 126
             /**
127 127
              * @filter `gravityview/data/parse/meta_keys`
@@ -129,11 +129,11 @@  discard block
 block discarded – undo
129 129
              * @deprecated
130 130
              * @see The `gravityview/view_collection/from_post/meta_keys` filter.
131 131
              */
132
-            $meta_keys = (array) apply_filters_deprecated('gravityview/data/parse/meta_keys', [$meta_keys, $post->ID], '2.0.7', 'gravityview/view_collection/from_post/meta_keys');
132
+            $meta_keys = (array)apply_filters_deprecated( 'gravityview/data/parse/meta_keys', [ $meta_keys, $post->ID ], '2.0.7', 'gravityview/view_collection/from_post/meta_keys' );
133 133
 
134 134
             /** What about inside post meta values? */
135
-            foreach ($meta_keys as $meta_key) {
136
-                $views = self::merge_deep($views, $post->{$meta_key});
135
+            foreach ( $meta_keys as $meta_key ) {
136
+                $views = self::merge_deep( $views, $post->{$meta_key});
137 137
             }
138 138
         }
139 139
 
@@ -150,18 +150,18 @@  discard block
 block discarded – undo
150 150
      *
151 151
      * @return \GV\View_Collection $views View Collection containing any additional Views found
152 152
      */
153
-    private static function merge_deep($views, $meta_value)
153
+    private static function merge_deep( $views, $meta_value )
154 154
     {
155
-        $meta_value = gv_maybe_json_decode($meta_value, true);
155
+        $meta_value = gv_maybe_json_decode( $meta_value, true );
156 156
 
157
-        if (is_array($meta_value)) {
158
-            foreach ($meta_value as $index => $item) {
159
-                $meta_value[$index] = self::merge_deep($views, $item);
157
+        if ( is_array( $meta_value ) ) {
158
+            foreach ( $meta_value as $index => $item ) {
159
+                $meta_value[ $index ] = self::merge_deep( $views, $item );
160 160
             }
161 161
         }
162 162
 
163
-        if (is_string($meta_value)) {
164
-            $views->merge(self::from_content($meta_value));
163
+        if ( is_string( $meta_value ) ) {
164
+            $views->merge( self::from_content( $meta_value ) );
165 165
         }
166 166
 
167 167
         return $views;
@@ -180,24 +180,24 @@  discard block
 block discarded – undo
180 180
      *
181 181
      * @return \GV\View_Collection A \GV\View_Collection instance containing the views inside the supplied \WP_Post.
182 182
      */
183
-    public static function from_content($content)
183
+    public static function from_content( $content )
184 184
     {
185 185
         $views = new self();
186 186
 
187 187
         /** Let's find us some [gravityview] shortcodes perhaps. */
188
-        foreach (Shortcode::parse($content) as $shortcode) {
189
-            if ($shortcode->name != 'gravityview' || empty($shortcode->atts['id'])) {
188
+        foreach ( Shortcode::parse( $content ) as $shortcode ) {
189
+            if ( $shortcode->name != 'gravityview' || empty( $shortcode->atts[ 'id' ] ) ) {
190 190
                 continue;
191 191
             }
192 192
 
193
-            if (is_numeric($shortcode->atts['id'])) {
194
-                $view = View::by_id($shortcode->atts['id']);
195
-                if (!$view) {
193
+            if ( is_numeric( $shortcode->atts[ 'id' ] ) ) {
194
+                $view = View::by_id( $shortcode->atts[ 'id' ] );
195
+                if ( ! $view ) {
196 196
                     continue;
197 197
                 }
198 198
 
199
-                $view->settings->update($shortcode->atts);
200
-                $views->add($view);
199
+                $view->settings->update( $shortcode->atts );
200
+                $views->add( $view );
201 201
             }
202 202
         }
203 203
 
Please login to merge, or discard this patch.
Braces   +8 added lines, -16 removed lines patch added patch discarded remove patch
@@ -10,15 +10,13 @@  discard block
 block discarded – undo
10 10
 /**
11 11
  * A collection of \GV\View objects.
12 12
  */
13
-class View_Collection extends Collection
14
-{
13
+class View_Collection extends Collection {
15 14
     /**
16 15
      * @inheritDoc
17 16
      *
18 17
      * @return View[]
19 18
      */
20
-    public function all()
21
-    {
19
+    public function all() {
22 20
         return parent::all();
23 21
     }
24 22
 
@@ -33,8 +31,7 @@  discard block
 block discarded – undo
33 31
      *
34 32
      * @return void
35 33
      */
36
-    public function add($view)
37
-    {
34
+    public function add($view) {
38 35
         if (!$view instanceof View) {
39 36
             gravityview()->log->error('View_Collections can only contain objects of type \GV\View.');
40 37
 
@@ -55,8 +52,7 @@  discard block
 block discarded – undo
55 52
      *
56 53
      * @return \GV\View|null The \GV\View with the $view_id as the ID, or null if not found.
57 54
      */
58
-    public function get($view_id)
59
-    {
55
+    public function get($view_id) {
60 56
         foreach ($this->all() as $view) {
61 57
             if ($view->ID == $view_id) {
62 58
                 return $view;
@@ -77,8 +73,7 @@  discard block
 block discarded – undo
77 73
      *
78 74
      * @return bool Whether it exists or not.
79 75
      */
80
-    public function contains($view_id)
81
-    {
76
+    public function contains($view_id) {
82 77
         return !is_null($this->get($view_id));
83 78
     }
84 79
 
@@ -97,8 +92,7 @@  discard block
 block discarded – undo
97 92
      *
98 93
      * @return \GV\View_Collection A \GV\View_Collection instance containing the views inside the supplied \WP_Post.
99 94
      */
100
-    public static function from_post(\WP_Post $post)
101
-    {
95
+    public static function from_post(\WP_Post $post) {
102 96
         $views = new self();
103 97
 
104 98
         $post_type = get_post_type($post);
@@ -150,8 +144,7 @@  discard block
 block discarded – undo
150 144
      *
151 145
      * @return \GV\View_Collection $views View Collection containing any additional Views found
152 146
      */
153
-    private static function merge_deep($views, $meta_value)
154
-    {
147
+    private static function merge_deep($views, $meta_value) {
155 148
         $meta_value = gv_maybe_json_decode($meta_value, true);
156 149
 
157 150
         if (is_array($meta_value)) {
@@ -180,8 +173,7 @@  discard block
 block discarded – undo
180 173
      *
181 174
      * @return \GV\View_Collection A \GV\View_Collection instance containing the views inside the supplied \WP_Post.
182 175
      */
183
-    public static function from_content($content)
184
-    {
176
+    public static function from_content($content) {
185 177
         $views = new self();
186 178
 
187 179
         /** Let's find us some [gravityview] shortcodes perhaps. */
Please login to merge, or discard this patch.
future/includes/class-gv-oembed.php 3 patches
Indentation   +331 added lines, -331 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 
5 5
 /** If this file is called directly, abort. */
6 6
 if (!defined('GRAVITYVIEW_DIR')) {
7
-    exit();
7
+	exit();
8 8
 }
9 9
 
10 10
 /**
@@ -12,179 +12,179 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class oEmbed
14 14
 {
15
-    public static $provider_url = '';
16
-
17
-    /**
18
-     * Initialize.
19
-     *
20
-     * Register the oEmbed handler and the provider.
21
-     * Fire off the provider handler if detected.
22
-     *
23
-     * @return void
24
-     */
25
-    public static function init()
26
-    {
27
-        self::$provider_url = add_query_arg('gv_oembed_provider', '1', site_url());
28
-
29
-        wp_embed_register_handler('gravityview_entry', self::get_entry_regex(), [__CLASS__, 'render'], 20000);
30
-        wp_oembed_add_provider(self::get_entry_regex(), self::$provider_url, true);
31
-
32
-        if (!empty($_GET['gv_oembed_provider']) && !empty($_GET['url'])) {
33
-            add_action('template_redirect', [__CLASS__, 'render_provider_request']);
34
-        }
35
-
36
-        add_action('pre_oembed_result', [__CLASS__, 'pre_oembed_result'], 11, 3);
37
-    }
38
-
39
-    /**
40
-     * Output a response as a provider for an entry oEmbed URL.
41
-     *
42
-     * For now we only output the JSON format and don't care about the size (width, height).
43
-     * Our only current use-case is for it to provide output to the Add Media / From URL box
44
-     *  in WordPress 4.8.
45
-     *
46
-     * @return void
47
-     */
48
-    public static function render_provider_request()
49
-    {
50
-        if (!empty($_GET['url'])) {
51
-            $url = $_GET['url'];
52
-        } else {
53
-            header('HTTP/1.0 404 Not Found');
54
-            exit;
55
-        }
56
-
57
-        /** Parse the URL to an entry and a view */
58
-        preg_match(self::get_entry_regex(), $url, $matches);
59
-        $result = self::parse_matches($matches, $url);
60
-        if (!$result || count($result) != 2) {
61
-            header('HTTP/1.0 404 Not Found');
62
-            exit;
63
-        }
64
-
65
-        list($view, $entry) = $result;
66
-
67
-        echo json_encode([
68
-            'version'       => '1.0',
69
-            'provider_name' => 'gravityview',
70
-            'provider_url'  => self::$provider_url,
71
-            'html'          => self::render_preview_notice().self::render_frontend($view, $entry),
72
-        ]);
73
-        exit;
74
-    }
75
-
76
-    /**
77
-     * Output the embed HTML.
78
-     *
79
-     * @param array  $matches The regex matches from the provided regex when calling wp_embed_register_handler()
80
-     * @param array  $attr    Embed attributes.
81
-     * @param string $url     The original URL that was matched by the regex.
82
-     * @param array  $rawattr The original unmodified attributes.
83
-     *
84
-     * @return string The embed HTML.
85
-     */
86
-    public static function render($matches, $attr, $url, $rawattr)
87
-    {
88
-        $result = self::parse_matches($matches, $url);
89
-
90
-        if (!$result || count($result) != 2) {
91
-            gravityview()->log->notice('View or entry could not be parsed in oEmbed url {url}', ['url' => $url, 'matches' => $matches]);
92
-
93
-            return __('You are not allowed to view this content.', 'gravityview');
94
-        }
95
-
96
-        list($view, $entry) = $result;
97
-
98
-        if (Request::is_ajax() && !Request::is_add_oembed_preview()) {
99
-            /** Render a nice placeholder in the Visual mode. */
100
-            return self::render_admin($view, $entry);
101
-        } elseif (Request::is_add_oembed_preview()) {
102
-            /** Prepend a preview notice in Add Media / From URL screen */
103
-            return self::render_preview_notice().self::render_frontend($view, $entry);
104
-        }
105
-
106
-        return self::render_frontend($view, $entry);
107
-    }
108
-
109
-    /**
110
-     * Parse oEmbed regex matches and return View and Entry.
111
-     *
112
-     * @param array  $matches The regex matches.
113
-     * @param string $url     The URL of the embed.
114
-     *
115
-     * @return array (\GV\View, \GV\Entry)
116
-     */
117
-    private static function parse_matches($matches, $url)
118
-    {
119
-        // If not using permalinks, re-assign values for matching groups
120
-        if (!empty($matches['entry_slug2'])) {
121
-            $matches['is_cpt'] = $matches['is_cpt2'];
122
-            $matches['slug'] = $matches['slug2'];
123
-            $matches['entry_slug'] = $matches['entry_slug2'];
124
-            unset($matches['is_cpt2'], $matches['slug2'], $matches['entry_slug2']);
125
-        }
126
-
127
-        if (empty($matches['entry_slug'])) {
128
-            gravityview()->log->error('Entry slug not parsed by regex.', ['data' => $matches]);
129
-
130
-            return null;
131
-        } else {
132
-            $entry_id = $matches['entry_slug'];
133
-        }
134
-
135
-        if (!$entry = \GV\GF_Entry::by_id($entry_id)) {
136
-            gravityview()->log->error('Invalid entry ID {entry_id}', ['entry_id' => $entry_id]);
137
-
138
-            return null;
139
-        }
140
-
141
-        $view = null;
142
-
143
-        if ($view_id = url_to_postid($url)) {
144
-            $view = \GV\View::by_id($view_id);
145
-        }
146
-
147
-        // Maybe it failed to find a GravityView CPT
148
-        if (!$view) {
149
-
150
-            // If the slug doesn't work, maybe using Plain permalinks and not the slug, only ID
151
-            if (is_numeric($matches['slug'])) {
152
-                $view = \GV\View::by_id($matches['slug']);
153
-            }
154
-
155
-            if (!$view) {
156
-                $view = \GV\View::from_post(get_page_by_path($matches['slug'], OBJECT, 'gravityview'));
157
-            }
158
-        }
159
-
160
-        if (!$view) {
161
-            gravityview()->log->error('Could not detect View from URL {url}', ['url' => $url, 'data' => $matches]);
162
-
163
-            return null;
164
-        }
165
-
166
-        return [$view, $entry];
167
-    }
168
-
169
-    /**
170
-     * Display a nice placeholder in the admin for the entry.
171
-     *
172
-     * @param \GV\View  $view  The View.
173
-     * @param \GV\Entry $entry The Entry.
174
-     *
175
-     * @return string A placeholder, with Mr. Floaty :)
176
-     */
177
-    private static function render_admin($view, $entry)
178
-    {
179
-
180
-        // Floaty the astronaut
181
-        $image = \GravityView_Admin::get_floaty();
182
-
183
-        $embed_heading = sprintf(esc_html__('Embed Entry %d', 'gravityview'), $entry->ID);
184
-
185
-        $embed_text = sprintf(esc_html__('This entry will be displayed as it is configured in View %d', 'gravityview'), $view->ID);
186
-
187
-        return '
15
+	public static $provider_url = '';
16
+
17
+	/**
18
+	 * Initialize.
19
+	 *
20
+	 * Register the oEmbed handler and the provider.
21
+	 * Fire off the provider handler if detected.
22
+	 *
23
+	 * @return void
24
+	 */
25
+	public static function init()
26
+	{
27
+		self::$provider_url = add_query_arg('gv_oembed_provider', '1', site_url());
28
+
29
+		wp_embed_register_handler('gravityview_entry', self::get_entry_regex(), [__CLASS__, 'render'], 20000);
30
+		wp_oembed_add_provider(self::get_entry_regex(), self::$provider_url, true);
31
+
32
+		if (!empty($_GET['gv_oembed_provider']) && !empty($_GET['url'])) {
33
+			add_action('template_redirect', [__CLASS__, 'render_provider_request']);
34
+		}
35
+
36
+		add_action('pre_oembed_result', [__CLASS__, 'pre_oembed_result'], 11, 3);
37
+	}
38
+
39
+	/**
40
+	 * Output a response as a provider for an entry oEmbed URL.
41
+	 *
42
+	 * For now we only output the JSON format and don't care about the size (width, height).
43
+	 * Our only current use-case is for it to provide output to the Add Media / From URL box
44
+	 *  in WordPress 4.8.
45
+	 *
46
+	 * @return void
47
+	 */
48
+	public static function render_provider_request()
49
+	{
50
+		if (!empty($_GET['url'])) {
51
+			$url = $_GET['url'];
52
+		} else {
53
+			header('HTTP/1.0 404 Not Found');
54
+			exit;
55
+		}
56
+
57
+		/** Parse the URL to an entry and a view */
58
+		preg_match(self::get_entry_regex(), $url, $matches);
59
+		$result = self::parse_matches($matches, $url);
60
+		if (!$result || count($result) != 2) {
61
+			header('HTTP/1.0 404 Not Found');
62
+			exit;
63
+		}
64
+
65
+		list($view, $entry) = $result;
66
+
67
+		echo json_encode([
68
+			'version'       => '1.0',
69
+			'provider_name' => 'gravityview',
70
+			'provider_url'  => self::$provider_url,
71
+			'html'          => self::render_preview_notice().self::render_frontend($view, $entry),
72
+		]);
73
+		exit;
74
+	}
75
+
76
+	/**
77
+	 * Output the embed HTML.
78
+	 *
79
+	 * @param array  $matches The regex matches from the provided regex when calling wp_embed_register_handler()
80
+	 * @param array  $attr    Embed attributes.
81
+	 * @param string $url     The original URL that was matched by the regex.
82
+	 * @param array  $rawattr The original unmodified attributes.
83
+	 *
84
+	 * @return string The embed HTML.
85
+	 */
86
+	public static function render($matches, $attr, $url, $rawattr)
87
+	{
88
+		$result = self::parse_matches($matches, $url);
89
+
90
+		if (!$result || count($result) != 2) {
91
+			gravityview()->log->notice('View or entry could not be parsed in oEmbed url {url}', ['url' => $url, 'matches' => $matches]);
92
+
93
+			return __('You are not allowed to view this content.', 'gravityview');
94
+		}
95
+
96
+		list($view, $entry) = $result;
97
+
98
+		if (Request::is_ajax() && !Request::is_add_oembed_preview()) {
99
+			/** Render a nice placeholder in the Visual mode. */
100
+			return self::render_admin($view, $entry);
101
+		} elseif (Request::is_add_oembed_preview()) {
102
+			/** Prepend a preview notice in Add Media / From URL screen */
103
+			return self::render_preview_notice().self::render_frontend($view, $entry);
104
+		}
105
+
106
+		return self::render_frontend($view, $entry);
107
+	}
108
+
109
+	/**
110
+	 * Parse oEmbed regex matches and return View and Entry.
111
+	 *
112
+	 * @param array  $matches The regex matches.
113
+	 * @param string $url     The URL of the embed.
114
+	 *
115
+	 * @return array (\GV\View, \GV\Entry)
116
+	 */
117
+	private static function parse_matches($matches, $url)
118
+	{
119
+		// If not using permalinks, re-assign values for matching groups
120
+		if (!empty($matches['entry_slug2'])) {
121
+			$matches['is_cpt'] = $matches['is_cpt2'];
122
+			$matches['slug'] = $matches['slug2'];
123
+			$matches['entry_slug'] = $matches['entry_slug2'];
124
+			unset($matches['is_cpt2'], $matches['slug2'], $matches['entry_slug2']);
125
+		}
126
+
127
+		if (empty($matches['entry_slug'])) {
128
+			gravityview()->log->error('Entry slug not parsed by regex.', ['data' => $matches]);
129
+
130
+			return null;
131
+		} else {
132
+			$entry_id = $matches['entry_slug'];
133
+		}
134
+
135
+		if (!$entry = \GV\GF_Entry::by_id($entry_id)) {
136
+			gravityview()->log->error('Invalid entry ID {entry_id}', ['entry_id' => $entry_id]);
137
+
138
+			return null;
139
+		}
140
+
141
+		$view = null;
142
+
143
+		if ($view_id = url_to_postid($url)) {
144
+			$view = \GV\View::by_id($view_id);
145
+		}
146
+
147
+		// Maybe it failed to find a GravityView CPT
148
+		if (!$view) {
149
+
150
+			// If the slug doesn't work, maybe using Plain permalinks and not the slug, only ID
151
+			if (is_numeric($matches['slug'])) {
152
+				$view = \GV\View::by_id($matches['slug']);
153
+			}
154
+
155
+			if (!$view) {
156
+				$view = \GV\View::from_post(get_page_by_path($matches['slug'], OBJECT, 'gravityview'));
157
+			}
158
+		}
159
+
160
+		if (!$view) {
161
+			gravityview()->log->error('Could not detect View from URL {url}', ['url' => $url, 'data' => $matches]);
162
+
163
+			return null;
164
+		}
165
+
166
+		return [$view, $entry];
167
+	}
168
+
169
+	/**
170
+	 * Display a nice placeholder in the admin for the entry.
171
+	 *
172
+	 * @param \GV\View  $view  The View.
173
+	 * @param \GV\Entry $entry The Entry.
174
+	 *
175
+	 * @return string A placeholder, with Mr. Floaty :)
176
+	 */
177
+	private static function render_admin($view, $entry)
178
+	{
179
+
180
+		// Floaty the astronaut
181
+		$image = \GravityView_Admin::get_floaty();
182
+
183
+		$embed_heading = sprintf(esc_html__('Embed Entry %d', 'gravityview'), $entry->ID);
184
+
185
+		$embed_text = sprintf(esc_html__('This entry will be displayed as it is configured in View %d', 'gravityview'), $view->ID);
186
+
187
+		return '
188 188
 		<div class="loading-placeholder" style="background-color:#e6f0f5;">
189 189
 			<h3 style="margin:0; padding:0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen-Sans, Ubuntu, Cantarell, \'Helvetica Neue\', sans-serif;">'.$image.$embed_heading.'</h3>
190 190
 			<p style="margin:0; padding:0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen-Sans, Ubuntu, Cantarell, \'Helvetica Neue\', sans-serif;">
@@ -192,161 +192,161 @@  discard block
 block discarded – undo
192 192
 			</p>
193 193
 			<br style="clear: both;">
194 194
 		</div>';
195
-    }
196
-
197
-    /**
198
-     * Generate a warning to users when previewing oEmbed in the Add Media modal.
199
-     *
200
-     * @return string HTML notice
201
-     */
202
-    private static function render_preview_notice()
203
-    {
204
-        $floaty = \GravityView_Admin::get_floaty();
205
-        $title = esc_html__('This will look better when it is embedded.', 'gravityview');
206
-        $message = esc_html__('Styles don\'t get loaded when being previewed, so the content below will look strange. Don\'t be concerned!', 'gravityview');
207
-
208
-        return '<div class="updated notice">'.$floaty.'<h3>'.$title.'</h3><p>'.$message.'</p><br style="clear:both;" /></div>';
209
-    }
210
-
211
-    /**
212
-     * Render the entry as an oEmbed.
213
-     *
214
-     * @param \GV\View  $view  The View.
215
-     * @param \GV\Entry $entry The Entry.
216
-     *
217
-     * @return string The rendered oEmbed.
218
-     */
219
-    private static function render_frontend($view, $entry)
220
-    {
221
-        /** Private, pending, draft, etc. */
222
-        $public_states = get_post_stati(['public' => true]);
223
-        if (!in_array($view->post_status, $public_states) && !\GVCommon::has_cap('read_gravityview', $view->ID)) {
224
-            gravityview()->log->notice('The current user cannot access this View #{view_id}', ['view_id' => $view->ID]);
225
-
226
-            return __('You are not allowed to view this content.', 'gravityview');
227
-        }
228
-
229
-        if ($entry && 'active' !== $entry['status']) {
230
-            gravityview()->log->notice('Entry ID #{entry_id} is not active', ['entry_id' => $entry->ID]);
231
-
232
-            return __('You are not allowed to view this content.', 'gravityview');
233
-        }
234
-
235
-        if ($view->settings->get('show_only_approved')) {
236
-            if (!\GravityView_Entry_Approval_Status::is_approved(gform_get_meta($entry->ID, \GravityView_Entry_Approval::meta_key))) {
237
-                gravityview()->log->error('Entry ID #{entry_id} is not approved for viewing', ['entry_id' => $entry->ID]);
238
-
239
-                return __('You are not allowed to view this content.', 'gravityview');
240
-            }
241
-        }
242
-
243
-        /**
244
-         * When this is embedded inside a view we should not display the widgets.
245
-         */
246
-        $request = gravityview()->request;
247
-        $is_reembedded = false; // Assume not embedded unless detected otherwise.
248
-        if (in_array(get_class($request), ['GV\Frontend_Request', 'GV\Mock_Request'])) {
249
-            if (($_view = $request->is_view()) && $_view->ID !== $view->ID) {
250
-                $is_reembedded = true;
251
-            }
252
-        }
253
-
254
-        /**
255
-         * Remove Widgets on a nested embedded View.
256
-         * Also, don't show widgets if we're embedding an entry.
257
-         */
258
-        if ($is_reembedded || $entry) {
259
-            $view->widgets = new \GV\Widget_Collection();
260
-        }
261
-
262
-        if ($request->is_edit_entry()) {
263
-            /**
264
-             * Based on code in our unit-tests.
265
-             * Mocks old context, etc.
266
-             */
267
-            $loader = \GravityView_Edit_Entry::getInstance();
268
-            $render = $loader->instances['render'];
269
-
270
-            $form = \GFAPI::get_form($entry['form_id']);
271
-
272
-            // @todo We really need to rewrite Edit Entry soon
273
-            \GravityView_View::$instance = null;
274
-            \GravityView_View_Data::$instance = null;
275
-
276
-            $data = \GravityView_View_Data::getInstance(get_post($view->ID));
277
-            $template = \GravityView_View::getInstance([
278
-                'form'    => $form,
279
-                'form_id' => $form['id'],
280
-                'view_id' => $view->ID,
281
-                'entries' => [$entry->as_entry()],
282
-                'atts'    => \GVCommon::get_template_settings($view->ID),
283
-            ]);
284
-
285
-            ob_start() && $render->init($data, \GV\Entry::by_id($entry['id']), $view);
286
-            $output = ob_get_clean(); // Render :)
287
-        } else {
288
-            /** Remove the back link. */
289
-            add_filter('gravityview/template/links/back/url', '__return_false');
290
-
291
-            $renderer = new \GV\Entry_Renderer();
292
-            $output = $renderer->render($entry, $view, gravityview()->request);
293
-            $output = sprintf('<div class="gravityview-oembed gravityview-oembed-entry gravityview-oembed-entry-%d">%s</div>', $entry->ID, $output);
294
-
295
-            remove_filter('gravityview/template/links/back/url', '__return_false');
296
-        }
297
-
298
-        return $output;
299
-    }
300
-
301
-    /**
302
-     * Generate the Regular expression that matches embedded entries.
303
-     *
304
-     * Generates different regex if using permalinks and if not using permalinks
305
-     *
306
-     * @return string Regex code
307
-     */
308
-    private static function get_entry_regex()
309
-    {
310
-        $entry_var_name = \GV\Entry::get_endpoint_name();
311
-
312
-        /**
313
-         * @filter `gravityview_slug` Modify the url part for a View. [Read the doc](https://docs.gravityview.co/article/62-changing-the-view-slug)
314
-         *
315
-         * @param string $rewrite_slug The slug shown in the URL
316
-         */
317
-        $rewrite_slug = apply_filters('gravityview_slug', 'view');
318
-
319
-        // Only support embeds for current site
320
-        $prefix = trailingslashit(home_url());
321
-
322
-        // Using permalinks
323
-        $using_permalinks = $prefix."(?P<is_cpt>{$rewrite_slug})?/?(?P<slug>.+?)/{$entry_var_name}/(?P<entry_slug>.+?)/?\$";
324
-
325
-        // Not using permalinks
326
-        $not_using_permalinks = $prefix."(?:index.php)?\?(?P<is_cpt2>[^=]+)=(?P<slug2>[^&]+)&entry=(?P<entry_slug2>[^&]+)\$";
327
-
328
-        // Catch either
329
-        $match_regex = "(?:{$using_permalinks}|{$not_using_permalinks})";
330
-
331
-        return '#'.$match_regex.'#i';
332
-    }
333
-
334
-    /**
335
-     * Internal oEmbed output, shortcircuit without proxying to the provider.
336
-     */
337
-    public static function pre_oembed_result($result, $url, $args)
338
-    {
339
-        if (!preg_match(self::get_entry_regex(), $url, $matches)) {
340
-            return $result;
341
-        }
342
-
343
-        $view_entry = self::parse_matches($matches, $url);
344
-        if (!$view_entry || count($view_entry) != 2) {
345
-            return $result;
346
-        }
347
-
348
-        list($view, $entry) = $view_entry;
349
-
350
-        return self::render_frontend($view, $entry);
351
-    }
195
+	}
196
+
197
+	/**
198
+	 * Generate a warning to users when previewing oEmbed in the Add Media modal.
199
+	 *
200
+	 * @return string HTML notice
201
+	 */
202
+	private static function render_preview_notice()
203
+	{
204
+		$floaty = \GravityView_Admin::get_floaty();
205
+		$title = esc_html__('This will look better when it is embedded.', 'gravityview');
206
+		$message = esc_html__('Styles don\'t get loaded when being previewed, so the content below will look strange. Don\'t be concerned!', 'gravityview');
207
+
208
+		return '<div class="updated notice">'.$floaty.'<h3>'.$title.'</h3><p>'.$message.'</p><br style="clear:both;" /></div>';
209
+	}
210
+
211
+	/**
212
+	 * Render the entry as an oEmbed.
213
+	 *
214
+	 * @param \GV\View  $view  The View.
215
+	 * @param \GV\Entry $entry The Entry.
216
+	 *
217
+	 * @return string The rendered oEmbed.
218
+	 */
219
+	private static function render_frontend($view, $entry)
220
+	{
221
+		/** Private, pending, draft, etc. */
222
+		$public_states = get_post_stati(['public' => true]);
223
+		if (!in_array($view->post_status, $public_states) && !\GVCommon::has_cap('read_gravityview', $view->ID)) {
224
+			gravityview()->log->notice('The current user cannot access this View #{view_id}', ['view_id' => $view->ID]);
225
+
226
+			return __('You are not allowed to view this content.', 'gravityview');
227
+		}
228
+
229
+		if ($entry && 'active' !== $entry['status']) {
230
+			gravityview()->log->notice('Entry ID #{entry_id} is not active', ['entry_id' => $entry->ID]);
231
+
232
+			return __('You are not allowed to view this content.', 'gravityview');
233
+		}
234
+
235
+		if ($view->settings->get('show_only_approved')) {
236
+			if (!\GravityView_Entry_Approval_Status::is_approved(gform_get_meta($entry->ID, \GravityView_Entry_Approval::meta_key))) {
237
+				gravityview()->log->error('Entry ID #{entry_id} is not approved for viewing', ['entry_id' => $entry->ID]);
238
+
239
+				return __('You are not allowed to view this content.', 'gravityview');
240
+			}
241
+		}
242
+
243
+		/**
244
+		 * When this is embedded inside a view we should not display the widgets.
245
+		 */
246
+		$request = gravityview()->request;
247
+		$is_reembedded = false; // Assume not embedded unless detected otherwise.
248
+		if (in_array(get_class($request), ['GV\Frontend_Request', 'GV\Mock_Request'])) {
249
+			if (($_view = $request->is_view()) && $_view->ID !== $view->ID) {
250
+				$is_reembedded = true;
251
+			}
252
+		}
253
+
254
+		/**
255
+		 * Remove Widgets on a nested embedded View.
256
+		 * Also, don't show widgets if we're embedding an entry.
257
+		 */
258
+		if ($is_reembedded || $entry) {
259
+			$view->widgets = new \GV\Widget_Collection();
260
+		}
261
+
262
+		if ($request->is_edit_entry()) {
263
+			/**
264
+			 * Based on code in our unit-tests.
265
+			 * Mocks old context, etc.
266
+			 */
267
+			$loader = \GravityView_Edit_Entry::getInstance();
268
+			$render = $loader->instances['render'];
269
+
270
+			$form = \GFAPI::get_form($entry['form_id']);
271
+
272
+			// @todo We really need to rewrite Edit Entry soon
273
+			\GravityView_View::$instance = null;
274
+			\GravityView_View_Data::$instance = null;
275
+
276
+			$data = \GravityView_View_Data::getInstance(get_post($view->ID));
277
+			$template = \GravityView_View::getInstance([
278
+				'form'    => $form,
279
+				'form_id' => $form['id'],
280
+				'view_id' => $view->ID,
281
+				'entries' => [$entry->as_entry()],
282
+				'atts'    => \GVCommon::get_template_settings($view->ID),
283
+			]);
284
+
285
+			ob_start() && $render->init($data, \GV\Entry::by_id($entry['id']), $view);
286
+			$output = ob_get_clean(); // Render :)
287
+		} else {
288
+			/** Remove the back link. */
289
+			add_filter('gravityview/template/links/back/url', '__return_false');
290
+
291
+			$renderer = new \GV\Entry_Renderer();
292
+			$output = $renderer->render($entry, $view, gravityview()->request);
293
+			$output = sprintf('<div class="gravityview-oembed gravityview-oembed-entry gravityview-oembed-entry-%d">%s</div>', $entry->ID, $output);
294
+
295
+			remove_filter('gravityview/template/links/back/url', '__return_false');
296
+		}
297
+
298
+		return $output;
299
+	}
300
+
301
+	/**
302
+	 * Generate the Regular expression that matches embedded entries.
303
+	 *
304
+	 * Generates different regex if using permalinks and if not using permalinks
305
+	 *
306
+	 * @return string Regex code
307
+	 */
308
+	private static function get_entry_regex()
309
+	{
310
+		$entry_var_name = \GV\Entry::get_endpoint_name();
311
+
312
+		/**
313
+		 * @filter `gravityview_slug` Modify the url part for a View. [Read the doc](https://docs.gravityview.co/article/62-changing-the-view-slug)
314
+		 *
315
+		 * @param string $rewrite_slug The slug shown in the URL
316
+		 */
317
+		$rewrite_slug = apply_filters('gravityview_slug', 'view');
318
+
319
+		// Only support embeds for current site
320
+		$prefix = trailingslashit(home_url());
321
+
322
+		// Using permalinks
323
+		$using_permalinks = $prefix."(?P<is_cpt>{$rewrite_slug})?/?(?P<slug>.+?)/{$entry_var_name}/(?P<entry_slug>.+?)/?\$";
324
+
325
+		// Not using permalinks
326
+		$not_using_permalinks = $prefix."(?:index.php)?\?(?P<is_cpt2>[^=]+)=(?P<slug2>[^&]+)&entry=(?P<entry_slug2>[^&]+)\$";
327
+
328
+		// Catch either
329
+		$match_regex = "(?:{$using_permalinks}|{$not_using_permalinks})";
330
+
331
+		return '#'.$match_regex.'#i';
332
+	}
333
+
334
+	/**
335
+	 * Internal oEmbed output, shortcircuit without proxying to the provider.
336
+	 */
337
+	public static function pre_oembed_result($result, $url, $args)
338
+	{
339
+		if (!preg_match(self::get_entry_regex(), $url, $matches)) {
340
+			return $result;
341
+		}
342
+
343
+		$view_entry = self::parse_matches($matches, $url);
344
+		if (!$view_entry || count($view_entry) != 2) {
345
+			return $result;
346
+		}
347
+
348
+		list($view, $entry) = $view_entry;
349
+
350
+		return self::render_frontend($view, $entry);
351
+	}
352 352
 }
Please login to merge, or discard this patch.
Spacing   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 namespace GV;
4 4
 
5 5
 /** If this file is called directly, abort. */
6
-if (!defined('GRAVITYVIEW_DIR')) {
6
+if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
7 7
     exit();
8 8
 }
9 9
 
@@ -24,16 +24,16 @@  discard block
 block discarded – undo
24 24
      */
25 25
     public static function init()
26 26
     {
27
-        self::$provider_url = add_query_arg('gv_oembed_provider', '1', site_url());
27
+        self::$provider_url = add_query_arg( 'gv_oembed_provider', '1', site_url() );
28 28
 
29
-        wp_embed_register_handler('gravityview_entry', self::get_entry_regex(), [__CLASS__, 'render'], 20000);
30
-        wp_oembed_add_provider(self::get_entry_regex(), self::$provider_url, true);
29
+        wp_embed_register_handler( 'gravityview_entry', self::get_entry_regex(), [ __CLASS__, 'render' ], 20000 );
30
+        wp_oembed_add_provider( self::get_entry_regex(), self::$provider_url, true );
31 31
 
32
-        if (!empty($_GET['gv_oembed_provider']) && !empty($_GET['url'])) {
33
-            add_action('template_redirect', [__CLASS__, 'render_provider_request']);
32
+        if ( ! empty( $_GET[ 'gv_oembed_provider' ] ) && ! empty( $_GET[ 'url' ] ) ) {
33
+            add_action( 'template_redirect', [ __CLASS__, 'render_provider_request' ] );
34 34
         }
35 35
 
36
-        add_action('pre_oembed_result', [__CLASS__, 'pre_oembed_result'], 11, 3);
36
+        add_action( 'pre_oembed_result', [ __CLASS__, 'pre_oembed_result' ], 11, 3 );
37 37
     }
38 38
 
39 39
     /**
@@ -47,29 +47,29 @@  discard block
 block discarded – undo
47 47
      */
48 48
     public static function render_provider_request()
49 49
     {
50
-        if (!empty($_GET['url'])) {
51
-            $url = $_GET['url'];
50
+        if ( ! empty( $_GET[ 'url' ] ) ) {
51
+            $url = $_GET[ 'url' ];
52 52
         } else {
53
-            header('HTTP/1.0 404 Not Found');
53
+            header( 'HTTP/1.0 404 Not Found' );
54 54
             exit;
55 55
         }
56 56
 
57 57
         /** Parse the URL to an entry and a view */
58
-        preg_match(self::get_entry_regex(), $url, $matches);
59
-        $result = self::parse_matches($matches, $url);
60
-        if (!$result || count($result) != 2) {
61
-            header('HTTP/1.0 404 Not Found');
58
+        preg_match( self::get_entry_regex(), $url, $matches );
59
+        $result = self::parse_matches( $matches, $url );
60
+        if ( ! $result || count( $result ) != 2 ) {
61
+            header( 'HTTP/1.0 404 Not Found' );
62 62
             exit;
63 63
         }
64 64
 
65
-        list($view, $entry) = $result;
65
+        list( $view, $entry ) = $result;
66 66
 
67
-        echo json_encode([
67
+        echo json_encode( [
68 68
             'version'       => '1.0',
69 69
             'provider_name' => 'gravityview',
70 70
             'provider_url'  => self::$provider_url,
71
-            'html'          => self::render_preview_notice().self::render_frontend($view, $entry),
72
-        ]);
71
+            'html'          => self::render_preview_notice() . self::render_frontend( $view, $entry ),
72
+        ] );
73 73
         exit;
74 74
     }
75 75
 
@@ -83,27 +83,27 @@  discard block
 block discarded – undo
83 83
      *
84 84
      * @return string The embed HTML.
85 85
      */
86
-    public static function render($matches, $attr, $url, $rawattr)
86
+    public static function render( $matches, $attr, $url, $rawattr )
87 87
     {
88
-        $result = self::parse_matches($matches, $url);
88
+        $result = self::parse_matches( $matches, $url );
89 89
 
90
-        if (!$result || count($result) != 2) {
91
-            gravityview()->log->notice('View or entry could not be parsed in oEmbed url {url}', ['url' => $url, 'matches' => $matches]);
90
+        if ( ! $result || count( $result ) != 2 ) {
91
+            gravityview()->log->notice( 'View or entry could not be parsed in oEmbed url {url}', [ 'url' => $url, 'matches' => $matches ] );
92 92
 
93
-            return __('You are not allowed to view this content.', 'gravityview');
93
+            return __( 'You are not allowed to view this content.', 'gravityview' );
94 94
         }
95 95
 
96
-        list($view, $entry) = $result;
96
+        list( $view, $entry ) = $result;
97 97
 
98
-        if (Request::is_ajax() && !Request::is_add_oembed_preview()) {
98
+        if ( Request::is_ajax() && ! Request::is_add_oembed_preview() ) {
99 99
             /** Render a nice placeholder in the Visual mode. */
100
-            return self::render_admin($view, $entry);
101
-        } elseif (Request::is_add_oembed_preview()) {
100
+            return self::render_admin( $view, $entry );
101
+        } elseif ( Request::is_add_oembed_preview() ) {
102 102
             /** Prepend a preview notice in Add Media / From URL screen */
103
-            return self::render_preview_notice().self::render_frontend($view, $entry);
103
+            return self::render_preview_notice() . self::render_frontend( $view, $entry );
104 104
         }
105 105
 
106
-        return self::render_frontend($view, $entry);
106
+        return self::render_frontend( $view, $entry );
107 107
     }
108 108
 
109 109
     /**
@@ -114,56 +114,56 @@  discard block
 block discarded – undo
114 114
      *
115 115
      * @return array (\GV\View, \GV\Entry)
116 116
      */
117
-    private static function parse_matches($matches, $url)
117
+    private static function parse_matches( $matches, $url )
118 118
     {
119 119
         // If not using permalinks, re-assign values for matching groups
120
-        if (!empty($matches['entry_slug2'])) {
121
-            $matches['is_cpt'] = $matches['is_cpt2'];
122
-            $matches['slug'] = $matches['slug2'];
123
-            $matches['entry_slug'] = $matches['entry_slug2'];
124
-            unset($matches['is_cpt2'], $matches['slug2'], $matches['entry_slug2']);
120
+        if ( ! empty( $matches[ 'entry_slug2' ] ) ) {
121
+            $matches[ 'is_cpt' ] = $matches[ 'is_cpt2' ];
122
+            $matches[ 'slug' ] = $matches[ 'slug2' ];
123
+            $matches[ 'entry_slug' ] = $matches[ 'entry_slug2' ];
124
+            unset( $matches[ 'is_cpt2' ], $matches[ 'slug2' ], $matches[ 'entry_slug2' ] );
125 125
         }
126 126
 
127
-        if (empty($matches['entry_slug'])) {
128
-            gravityview()->log->error('Entry slug not parsed by regex.', ['data' => $matches]);
127
+        if ( empty( $matches[ 'entry_slug' ] ) ) {
128
+            gravityview()->log->error( 'Entry slug not parsed by regex.', [ 'data' => $matches ] );
129 129
 
130 130
             return null;
131 131
         } else {
132
-            $entry_id = $matches['entry_slug'];
132
+            $entry_id = $matches[ 'entry_slug' ];
133 133
         }
134 134
 
135
-        if (!$entry = \GV\GF_Entry::by_id($entry_id)) {
136
-            gravityview()->log->error('Invalid entry ID {entry_id}', ['entry_id' => $entry_id]);
135
+        if ( ! $entry = \GV\GF_Entry::by_id( $entry_id ) ) {
136
+            gravityview()->log->error( 'Invalid entry ID {entry_id}', [ 'entry_id' => $entry_id ] );
137 137
 
138 138
             return null;
139 139
         }
140 140
 
141 141
         $view = null;
142 142
 
143
-        if ($view_id = url_to_postid($url)) {
144
-            $view = \GV\View::by_id($view_id);
143
+        if ( $view_id = url_to_postid( $url ) ) {
144
+            $view = \GV\View::by_id( $view_id );
145 145
         }
146 146
 
147 147
         // Maybe it failed to find a GravityView CPT
148
-        if (!$view) {
148
+        if ( ! $view ) {
149 149
 
150 150
             // If the slug doesn't work, maybe using Plain permalinks and not the slug, only ID
151
-            if (is_numeric($matches['slug'])) {
152
-                $view = \GV\View::by_id($matches['slug']);
151
+            if ( is_numeric( $matches[ 'slug' ] ) ) {
152
+                $view = \GV\View::by_id( $matches[ 'slug' ] );
153 153
             }
154 154
 
155
-            if (!$view) {
156
-                $view = \GV\View::from_post(get_page_by_path($matches['slug'], OBJECT, 'gravityview'));
155
+            if ( ! $view ) {
156
+                $view = \GV\View::from_post( get_page_by_path( $matches[ 'slug' ], OBJECT, 'gravityview' ) );
157 157
             }
158 158
         }
159 159
 
160
-        if (!$view) {
161
-            gravityview()->log->error('Could not detect View from URL {url}', ['url' => $url, 'data' => $matches]);
160
+        if ( ! $view ) {
161
+            gravityview()->log->error( 'Could not detect View from URL {url}', [ 'url' => $url, 'data' => $matches ] );
162 162
 
163 163
             return null;
164 164
         }
165 165
 
166
-        return [$view, $entry];
166
+        return [ $view, $entry ];
167 167
     }
168 168
 
169 169
     /**
@@ -174,21 +174,21 @@  discard block
 block discarded – undo
174 174
      *
175 175
      * @return string A placeholder, with Mr. Floaty :)
176 176
      */
177
-    private static function render_admin($view, $entry)
177
+    private static function render_admin( $view, $entry )
178 178
     {
179 179
 
180 180
         // Floaty the astronaut
181 181
         $image = \GravityView_Admin::get_floaty();
182 182
 
183
-        $embed_heading = sprintf(esc_html__('Embed Entry %d', 'gravityview'), $entry->ID);
183
+        $embed_heading = sprintf( esc_html__( 'Embed Entry %d', 'gravityview' ), $entry->ID );
184 184
 
185
-        $embed_text = sprintf(esc_html__('This entry will be displayed as it is configured in View %d', 'gravityview'), $view->ID);
185
+        $embed_text = sprintf( esc_html__( 'This entry will be displayed as it is configured in View %d', 'gravityview' ), $view->ID );
186 186
 
187 187
         return '
188 188
 		<div class="loading-placeholder" style="background-color:#e6f0f5;">
189
-			<h3 style="margin:0; padding:0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen-Sans, Ubuntu, Cantarell, \'Helvetica Neue\', sans-serif;">'.$image.$embed_heading.'</h3>
189
+			<h3 style="margin:0; padding:0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen-Sans, Ubuntu, Cantarell, \'Helvetica Neue\', sans-serif;">'.$image . $embed_heading . '</h3>
190 190
 			<p style="margin:0; padding:0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen-Sans, Ubuntu, Cantarell, \'Helvetica Neue\', sans-serif;">
191
-				'.$embed_text.'
191
+				'.$embed_text . '
192 192
 			</p>
193 193
 			<br style="clear: both;">
194 194
 		</div>';
@@ -202,10 +202,10 @@  discard block
 block discarded – undo
202 202
     private static function render_preview_notice()
203 203
     {
204 204
         $floaty = \GravityView_Admin::get_floaty();
205
-        $title = esc_html__('This will look better when it is embedded.', 'gravityview');
206
-        $message = esc_html__('Styles don\'t get loaded when being previewed, so the content below will look strange. Don\'t be concerned!', 'gravityview');
205
+        $title = esc_html__( 'This will look better when it is embedded.', 'gravityview' );
206
+        $message = esc_html__( 'Styles don\'t get loaded when being previewed, so the content below will look strange. Don\'t be concerned!', 'gravityview' );
207 207
 
208
-        return '<div class="updated notice">'.$floaty.'<h3>'.$title.'</h3><p>'.$message.'</p><br style="clear:both;" /></div>';
208
+        return '<div class="updated notice">' . $floaty . '<h3>' . $title . '</h3><p>' . $message . '</p><br style="clear:both;" /></div>';
209 209
     }
210 210
 
211 211
     /**
@@ -216,27 +216,27 @@  discard block
 block discarded – undo
216 216
      *
217 217
      * @return string The rendered oEmbed.
218 218
      */
219
-    private static function render_frontend($view, $entry)
219
+    private static function render_frontend( $view, $entry )
220 220
     {
221 221
         /** Private, pending, draft, etc. */
222
-        $public_states = get_post_stati(['public' => true]);
223
-        if (!in_array($view->post_status, $public_states) && !\GVCommon::has_cap('read_gravityview', $view->ID)) {
224
-            gravityview()->log->notice('The current user cannot access this View #{view_id}', ['view_id' => $view->ID]);
222
+        $public_states = get_post_stati( [ 'public' => true ] );
223
+        if ( ! in_array( $view->post_status, $public_states ) && ! \GVCommon::has_cap( 'read_gravityview', $view->ID ) ) {
224
+            gravityview()->log->notice( 'The current user cannot access this View #{view_id}', [ 'view_id' => $view->ID ] );
225 225
 
226
-            return __('You are not allowed to view this content.', 'gravityview');
226
+            return __( 'You are not allowed to view this content.', 'gravityview' );
227 227
         }
228 228
 
229
-        if ($entry && 'active' !== $entry['status']) {
230
-            gravityview()->log->notice('Entry ID #{entry_id} is not active', ['entry_id' => $entry->ID]);
229
+        if ( $entry && 'active' !== $entry[ 'status' ] ) {
230
+            gravityview()->log->notice( 'Entry ID #{entry_id} is not active', [ 'entry_id' => $entry->ID ] );
231 231
 
232
-            return __('You are not allowed to view this content.', 'gravityview');
232
+            return __( 'You are not allowed to view this content.', 'gravityview' );
233 233
         }
234 234
 
235
-        if ($view->settings->get('show_only_approved')) {
236
-            if (!\GravityView_Entry_Approval_Status::is_approved(gform_get_meta($entry->ID, \GravityView_Entry_Approval::meta_key))) {
237
-                gravityview()->log->error('Entry ID #{entry_id} is not approved for viewing', ['entry_id' => $entry->ID]);
235
+        if ( $view->settings->get( 'show_only_approved' ) ) {
236
+            if ( ! \GravityView_Entry_Approval_Status::is_approved( gform_get_meta( $entry->ID, \GravityView_Entry_Approval::meta_key ) ) ) {
237
+                gravityview()->log->error( 'Entry ID #{entry_id} is not approved for viewing', [ 'entry_id' => $entry->ID ] );
238 238
 
239
-                return __('You are not allowed to view this content.', 'gravityview');
239
+                return __( 'You are not allowed to view this content.', 'gravityview' );
240 240
             }
241 241
         }
242 242
 
@@ -245,8 +245,8 @@  discard block
 block discarded – undo
245 245
          */
246 246
         $request = gravityview()->request;
247 247
         $is_reembedded = false; // Assume not embedded unless detected otherwise.
248
-        if (in_array(get_class($request), ['GV\Frontend_Request', 'GV\Mock_Request'])) {
249
-            if (($_view = $request->is_view()) && $_view->ID !== $view->ID) {
248
+        if ( in_array( get_class( $request ), [ 'GV\Frontend_Request', 'GV\Mock_Request' ] ) ) {
249
+            if ( ( $_view = $request->is_view() ) && $_view->ID !== $view->ID ) {
250 250
                 $is_reembedded = true;
251 251
             }
252 252
         }
@@ -255,44 +255,44 @@  discard block
 block discarded – undo
255 255
          * Remove Widgets on a nested embedded View.
256 256
          * Also, don't show widgets if we're embedding an entry.
257 257
          */
258
-        if ($is_reembedded || $entry) {
258
+        if ( $is_reembedded || $entry ) {
259 259
             $view->widgets = new \GV\Widget_Collection();
260 260
         }
261 261
 
262
-        if ($request->is_edit_entry()) {
262
+        if ( $request->is_edit_entry() ) {
263 263
             /**
264 264
              * Based on code in our unit-tests.
265 265
              * Mocks old context, etc.
266 266
              */
267 267
             $loader = \GravityView_Edit_Entry::getInstance();
268
-            $render = $loader->instances['render'];
268
+            $render = $loader->instances[ 'render' ];
269 269
 
270
-            $form = \GFAPI::get_form($entry['form_id']);
270
+            $form = \GFAPI::get_form( $entry[ 'form_id' ] );
271 271
 
272 272
             // @todo We really need to rewrite Edit Entry soon
273 273
             \GravityView_View::$instance = null;
274 274
             \GravityView_View_Data::$instance = null;
275 275
 
276
-            $data = \GravityView_View_Data::getInstance(get_post($view->ID));
277
-            $template = \GravityView_View::getInstance([
276
+            $data = \GravityView_View_Data::getInstance( get_post( $view->ID ) );
277
+            $template = \GravityView_View::getInstance( [
278 278
                 'form'    => $form,
279
-                'form_id' => $form['id'],
279
+                'form_id' => $form[ 'id' ],
280 280
                 'view_id' => $view->ID,
281
-                'entries' => [$entry->as_entry()],
282
-                'atts'    => \GVCommon::get_template_settings($view->ID),
283
-            ]);
281
+                'entries' => [ $entry->as_entry() ],
282
+                'atts'    => \GVCommon::get_template_settings( $view->ID ),
283
+            ] );
284 284
 
285
-            ob_start() && $render->init($data, \GV\Entry::by_id($entry['id']), $view);
285
+            ob_start() && $render->init( $data, \GV\Entry::by_id( $entry[ 'id' ] ), $view );
286 286
             $output = ob_get_clean(); // Render :)
287 287
         } else {
288 288
             /** Remove the back link. */
289
-            add_filter('gravityview/template/links/back/url', '__return_false');
289
+            add_filter( 'gravityview/template/links/back/url', '__return_false' );
290 290
 
291 291
             $renderer = new \GV\Entry_Renderer();
292
-            $output = $renderer->render($entry, $view, gravityview()->request);
293
-            $output = sprintf('<div class="gravityview-oembed gravityview-oembed-entry gravityview-oembed-entry-%d">%s</div>', $entry->ID, $output);
292
+            $output = $renderer->render( $entry, $view, gravityview()->request );
293
+            $output = sprintf( '<div class="gravityview-oembed gravityview-oembed-entry gravityview-oembed-entry-%d">%s</div>', $entry->ID, $output );
294 294
 
295
-            remove_filter('gravityview/template/links/back/url', '__return_false');
295
+            remove_filter( 'gravityview/template/links/back/url', '__return_false' );
296 296
         }
297 297
 
298 298
         return $output;
@@ -314,39 +314,39 @@  discard block
 block discarded – undo
314 314
          *
315 315
          * @param string $rewrite_slug The slug shown in the URL
316 316
          */
317
-        $rewrite_slug = apply_filters('gravityview_slug', 'view');
317
+        $rewrite_slug = apply_filters( 'gravityview_slug', 'view' );
318 318
 
319 319
         // Only support embeds for current site
320
-        $prefix = trailingslashit(home_url());
320
+        $prefix = trailingslashit( home_url() );
321 321
 
322 322
         // Using permalinks
323
-        $using_permalinks = $prefix."(?P<is_cpt>{$rewrite_slug})?/?(?P<slug>.+?)/{$entry_var_name}/(?P<entry_slug>.+?)/?\$";
323
+        $using_permalinks = $prefix . "(?P<is_cpt>{$rewrite_slug})?/?(?P<slug>.+?)/{$entry_var_name}/(?P<entry_slug>.+?)/?\$";
324 324
 
325 325
         // Not using permalinks
326
-        $not_using_permalinks = $prefix."(?:index.php)?\?(?P<is_cpt2>[^=]+)=(?P<slug2>[^&]+)&entry=(?P<entry_slug2>[^&]+)\$";
326
+        $not_using_permalinks = $prefix . "(?:index.php)?\?(?P<is_cpt2>[^=]+)=(?P<slug2>[^&]+)&entry=(?P<entry_slug2>[^&]+)\$";
327 327
 
328 328
         // Catch either
329 329
         $match_regex = "(?:{$using_permalinks}|{$not_using_permalinks})";
330 330
 
331
-        return '#'.$match_regex.'#i';
331
+        return '#' . $match_regex . '#i';
332 332
     }
333 333
 
334 334
     /**
335 335
      * Internal oEmbed output, shortcircuit without proxying to the provider.
336 336
      */
337
-    public static function pre_oembed_result($result, $url, $args)
337
+    public static function pre_oembed_result( $result, $url, $args )
338 338
     {
339
-        if (!preg_match(self::get_entry_regex(), $url, $matches)) {
339
+        if ( ! preg_match( self::get_entry_regex(), $url, $matches ) ) {
340 340
             return $result;
341 341
         }
342 342
 
343
-        $view_entry = self::parse_matches($matches, $url);
344
-        if (!$view_entry || count($view_entry) != 2) {
343
+        $view_entry = self::parse_matches( $matches, $url );
344
+        if ( ! $view_entry || count( $view_entry ) != 2 ) {
345 345
             return $result;
346 346
         }
347 347
 
348
-        list($view, $entry) = $view_entry;
348
+        list( $view, $entry ) = $view_entry;
349 349
 
350
-        return self::render_frontend($view, $entry);
350
+        return self::render_frontend( $view, $entry );
351 351
     }
352 352
 }
Please login to merge, or discard this patch.
Braces   +10 added lines, -20 removed lines patch added patch discarded remove patch
@@ -10,8 +10,7 @@  discard block
 block discarded – undo
10 10
 /**
11 11
  * oEmbed functionality for GravityView.
12 12
  */
13
-class oEmbed
14
-{
13
+class oEmbed {
15 14
     public static $provider_url = '';
16 15
 
17 16
     /**
@@ -22,8 +21,7 @@  discard block
 block discarded – undo
22 21
      *
23 22
      * @return void
24 23
      */
25
-    public static function init()
26
-    {
24
+    public static function init() {
27 25
         self::$provider_url = add_query_arg('gv_oembed_provider', '1', site_url());
28 26
 
29 27
         wp_embed_register_handler('gravityview_entry', self::get_entry_regex(), [__CLASS__, 'render'], 20000);
@@ -45,8 +43,7 @@  discard block
 block discarded – undo
45 43
      *
46 44
      * @return void
47 45
      */
48
-    public static function render_provider_request()
49
-    {
46
+    public static function render_provider_request() {
50 47
         if (!empty($_GET['url'])) {
51 48
             $url = $_GET['url'];
52 49
         } else {
@@ -83,8 +80,7 @@  discard block
 block discarded – undo
83 80
      *
84 81
      * @return string The embed HTML.
85 82
      */
86
-    public static function render($matches, $attr, $url, $rawattr)
87
-    {
83
+    public static function render($matches, $attr, $url, $rawattr) {
88 84
         $result = self::parse_matches($matches, $url);
89 85
 
90 86
         if (!$result || count($result) != 2) {
@@ -114,8 +110,7 @@  discard block
 block discarded – undo
114 110
      *
115 111
      * @return array (\GV\View, \GV\Entry)
116 112
      */
117
-    private static function parse_matches($matches, $url)
118
-    {
113
+    private static function parse_matches($matches, $url) {
119 114
         // If not using permalinks, re-assign values for matching groups
120 115
         if (!empty($matches['entry_slug2'])) {
121 116
             $matches['is_cpt'] = $matches['is_cpt2'];
@@ -174,8 +169,7 @@  discard block
 block discarded – undo
174 169
      *
175 170
      * @return string A placeholder, with Mr. Floaty :)
176 171
      */
177
-    private static function render_admin($view, $entry)
178
-    {
172
+    private static function render_admin($view, $entry) {
179 173
 
180 174
         // Floaty the astronaut
181 175
         $image = \GravityView_Admin::get_floaty();
@@ -199,8 +193,7 @@  discard block
 block discarded – undo
199 193
      *
200 194
      * @return string HTML notice
201 195
      */
202
-    private static function render_preview_notice()
203
-    {
196
+    private static function render_preview_notice() {
204 197
         $floaty = \GravityView_Admin::get_floaty();
205 198
         $title = esc_html__('This will look better when it is embedded.', 'gravityview');
206 199
         $message = esc_html__('Styles don\'t get loaded when being previewed, so the content below will look strange. Don\'t be concerned!', 'gravityview');
@@ -216,8 +209,7 @@  discard block
 block discarded – undo
216 209
      *
217 210
      * @return string The rendered oEmbed.
218 211
      */
219
-    private static function render_frontend($view, $entry)
220
-    {
212
+    private static function render_frontend($view, $entry) {
221 213
         /** Private, pending, draft, etc. */
222 214
         $public_states = get_post_stati(['public' => true]);
223 215
         if (!in_array($view->post_status, $public_states) && !\GVCommon::has_cap('read_gravityview', $view->ID)) {
@@ -305,8 +297,7 @@  discard block
 block discarded – undo
305 297
      *
306 298
      * @return string Regex code
307 299
      */
308
-    private static function get_entry_regex()
309
-    {
300
+    private static function get_entry_regex() {
310 301
         $entry_var_name = \GV\Entry::get_endpoint_name();
311 302
 
312 303
         /**
@@ -334,8 +325,7 @@  discard block
 block discarded – undo
334 325
     /**
335 326
      * Internal oEmbed output, shortcircuit without proxying to the provider.
336 327
      */
337
-    public static function pre_oembed_result($result, $url, $args)
338
-    {
328
+    public static function pre_oembed_result($result, $url, $args) {
339 329
         if (!preg_match(self::get_entry_regex(), $url, $matches)) {
340 330
             return $result;
341 331
         }
Please login to merge, or discard this patch.