Completed
Pull Request — develop (#600)
by Zack
04:03
created
templates/fields/date_created.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -8,16 +8,16 @@  discard block
 block discarded – undo
8 8
 
9 9
 $gravityview_view = GravityView_View::getInstance();
10 10
 
11
-extract( $gravityview_view->getCurrentField() );
11
+extract($gravityview_view->getCurrentField());
12 12
 
13 13
 
14 14
 
15
-if( !empty( $field_settings ) && !empty( $field_settings['date_display'] ) && !empty( $value ) ) {
15
+if (!empty($field_settings) && !empty($field_settings['date_display']) && !empty($value)) {
16 16
 
17 17
 	// If there is a custom PHP date format passed via the date_display setting,
18 18
 	// use PHP's date format
19 19
 	$format = $field_settings['date_display'];
20
-	$output = date_i18n( $format, strtotime( $tz_value ) );
20
+	$output = date_i18n($format, strtotime($tz_value));
21 21
 
22 22
 } else {
23 23
 
@@ -26,8 +26,8 @@  discard block
 block discarded – undo
26 26
 	 * @see https://codex.wordpress.org/Formatting_Date_and_Time
27 27
 	 * @param null|string Date Format (default: $field->dateFormat)
28 28
 	 */
29
-	$format = apply_filters( 'gravityview_date_format', rgar($field, "dateFormat") );
30
-	$output = GFCommon::date_display( $tz_value, $format );
29
+	$format = apply_filters('gravityview_date_format', rgar($field, "dateFormat"));
30
+	$output = GFCommon::date_display($tz_value, $format);
31 31
 
32 32
 }
33 33
 
Please login to merge, or discard this patch.
includes/fields/class-gravityview-field-date-created.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -4,33 +4,33 @@  discard block
 block discarded – undo
4 4
 
5 5
 	var $name = 'date_created';
6 6
 
7
-	var $search_operators = array( 'less_than', 'greater_than', 'is', 'isnot' );
7
+	var $search_operators = array('less_than', 'greater_than', 'is', 'isnot');
8 8
 
9 9
 	var $group = 'meta';
10 10
 
11
-	var $contexts = array( 'single', 'multiple', 'export' );
11
+	var $contexts = array('single', 'multiple', 'export');
12 12
 
13 13
 	/**
14 14
 	 * GravityView_Field_Date_Created constructor.
15 15
 	 */
16 16
 	public function __construct() {
17
-		$this->label = esc_attr__( 'Date Created', 'gravityview' );
18
-		$this->description = esc_attr__( 'The date the entry was created.', 'gravityview' );
17
+		$this->label = esc_attr__('Date Created', 'gravityview');
18
+		$this->description = esc_attr__('The date the entry was created.', 'gravityview');
19 19
 		parent::__construct();
20 20
 	}
21 21
 
22
-	function field_options( $field_options, $template_id, $field_id, $context, $input_type ) {
22
+	function field_options($field_options, $template_id, $field_id, $context, $input_type) {
23 23
 
24
-		if( 'edit' === $context ) {
24
+		if ('edit' === $context) {
25 25
 			return $field_options;
26 26
 		}
27 27
 
28
-		$this->add_field_support('date_display', $field_options );
28
+		$this->add_field_support('date_display', $field_options);
29 29
 
30 30
 		return $field_options;
31 31
 	}
32 32
 
33
-	public static function format( $value, $format = '', $context = 'display' ) {
33
+	public static function format($value, $format = '', $context = 'display') {
34 34
 
35 35
 		/**
36 36
 		 * @filter `gravityview_date_created_adjust_timezone` Whether to adjust the timezone for entries. \n
@@ -39,16 +39,16 @@  discard block
 block discarded – undo
39 39
 		 * @param[out,in] boolean $adjust_tz  Use timezone-adjusted datetime? If true, adjusts date based on blog's timezone setting. If false, uses UTC setting. Default: true
40 40
 		 * @param[in] string $context Where the filter is being called from. `display` in this case.
41 41
 		 */
42
-		$adjust_tz = apply_filters( 'gravityview_date_created_adjust_timezone', true, $context );
42
+		$adjust_tz = apply_filters('gravityview_date_created_adjust_timezone', true, $context);
43 43
 
44 44
 		/**
45 45
 		 * date_created is stored in UTC format. Fetch in the current blog's timezone if $adjust_tz is true
46 46
 		 */
47
-		$tz_value = $adjust_tz ? get_date_from_gmt( $value ) : $value;
47
+		$tz_value = $adjust_tz ? get_date_from_gmt($value) : $value;
48 48
 
49
-		if( $format ) {
49
+		if ($format) {
50 50
 
51
-			$output = date_i18n( $format, strtotime( $tz_value ) );
51
+			$output = date_i18n($format, strtotime($tz_value));
52 52
 
53 53
 		} else {
54 54
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 			 * @see https://codex.wordpress.org/Formatting_Date_and_Time
58 58
 			 * @param null|string Date Format (default: $field->dateFormat)
59 59
 			 */
60
-			$format = apply_filters( 'gravityview_date_format', rgar($field, "dateFormat") );
60
+			$format = apply_filters('gravityview_date_format', rgar($field, "dateFormat"));
61 61
 
62
-			$output = GFCommon::date_display( $tz_value, $format );
62
+			$output = GFCommon::date_display($tz_value, $format);
63 63
 		}
64 64
 
65 65
 		return $output;
Please login to merge, or discard this patch.
includes/class-gravityview-merge-tags.php 1 patch
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -19,10 +19,10 @@  discard block
 block discarded – undo
19 19
 	 */
20 20
 	private function add_hooks() {
21 21
 
22
-		add_filter( 'gform_custom_merge_tags', array( $this, '_gform_custom_merge_tags' ), 10, 4 );
22
+		add_filter('gform_custom_merge_tags', array($this, '_gform_custom_merge_tags'), 10, 4);
23 23
 
24 24
 		/** @see GFCommon::replace_variables_prepopulate **/
25
-		add_filter( 'gform_replace_merge_tags', array( 'GravityView_Merge_Tags', 'replace_gv_merge_tags' ), 10, 7 );
25
+		add_filter('gform_replace_merge_tags', array('GravityView_Merge_Tags', 'replace_gv_merge_tags'), 10, 7);
26 26
 
27 27
 	}
28 28
 
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	 * @param  bool       $esc_html     Pass return value through `esc_html()`
44 44
 	 * @return string                  Text with variables maybe replaced
45 45
 	 */
46
-	public static function replace_variables($text, $form = array(), $entry = array(), $url_encode = false, $esc_html = true ) {
46
+	public static function replace_variables($text, $form = array(), $entry = array(), $url_encode = false, $esc_html = true) {
47 47
 
48 48
 		/**
49 49
 		 * @filter `gravityview_do_replace_variables` Turn off merge tag variable replacements.\n
@@ -55,9 +55,9 @@  discard block
 block discarded – undo
55 55
 		 * @param[in]  array      $form        GF Form array
56 56
 		 * @param[in]  array      $entry        GF Entry array
57 57
 		 */
58
-		$do_replace_variables = apply_filters( 'gravityview/merge_tags/do_replace_variables', true, $text, $form, $entry );
58
+		$do_replace_variables = apply_filters('gravityview/merge_tags/do_replace_variables', true, $text, $form, $entry);
59 59
 
60
-		if ( strpos( $text, '{' ) === false || ! $do_replace_variables ) {
60
+		if (strpos($text, '{') === false || !$do_replace_variables) {
61 61
 			return $text;
62 62
 		}
63 63
 
@@ -66,11 +66,11 @@  discard block
 block discarded – undo
66 66
 		 *
67 67
 		 * @internal Reported to GF Support on 12/3
68 68
 		 */
69
-		$form['title']  = isset( $form['title'] ) ? $form['title'] : '';
70
-		$form['id']     = isset( $form['id'] ) ? $form['id'] : '';
71
-		$form['fields'] = isset( $form['fields'] ) ? $form['fields'] : array();
69
+		$form['title']  = isset($form['title']) ? $form['title'] : '';
70
+		$form['id']     = isset($form['id']) ? $form['id'] : '';
71
+		$form['fields'] = isset($form['fields']) ? $form['fields'] : array();
72 72
 
73
-		return GFCommon::replace_variables( $text, $form, $entry, $url_encode, $esc_html );
73
+		return GFCommon::replace_variables($text, $form, $entry, $url_encode, $esc_html);
74 74
 	}
75 75
 
76 76
 	/**
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 	 *
86 86
 	 * @return array Modified merge tags
87 87
 	 */
88
-	public function _gform_custom_merge_tags( $existing_merge_tags = array(), $form_id, $fields = array(), $element_id = '' ) {
88
+	public function _gform_custom_merge_tags($existing_merge_tags = array(), $form_id, $fields = array(), $element_id = '') {
89 89
 
90 90
 		$created_by_merge_tags = array(
91 91
 			array(
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 		);
120 120
 
121 121
 		//return the form object from the php hook
122
-		return array_merge( $existing_merge_tags, $created_by_merge_tags );
122
+		return array_merge($existing_merge_tags, $created_by_merge_tags);
123 123
 	}
124 124
 
125 125
 	/**
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 	 *
138 138
 	 * @return mixed
139 139
 	 */
140
-	public static function replace_gv_merge_tags(  $text, $form = array(), $entry = array(), $url_encode = false, $esc_html = false ) {
140
+	public static function replace_gv_merge_tags($text, $form = array(), $entry = array(), $url_encode = false, $esc_html = false) {
141 141
 
142 142
 		/**
143 143
 		 * This prevents the gform_replace_merge_tags filter from being called twice, as defined in:
@@ -145,16 +145,16 @@  discard block
 block discarded – undo
145 145
 		 * @see GFCommon::replace_variables_prepopulate()
146 146
 		 * @todo Remove eventually: Gravity Forms fixed this issue in 1.9.14
147 147
 		 */
148
-		if( false === $form ) {
148
+		if (false === $form) {
149 149
 			return $text;
150 150
 		}
151 151
 
152
-		$text = self::replace_get_variables( $text, $form, $entry, $url_encode );
152
+		$text = self::replace_get_variables($text, $form, $entry, $url_encode);
153 153
 
154 154
 		// Process the merge vars here
155
-		$text = self::replace_user_variables_created_by( $text, $form, $entry, $url_encode, $esc_html );
155
+		$text = self::replace_user_variables_created_by($text, $form, $entry, $url_encode, $esc_html);
156 156
 
157
-		$text = self::replace_date_created( $text, $form, $entry, $url_encode, $esc_html );
157
+		$text = self::replace_date_created($text, $form, $entry, $url_encode, $esc_html);
158 158
 
159 159
 		return $text;
160 160
 	}
@@ -173,62 +173,62 @@  discard block
 block discarded – undo
173 173
 	 *
174 174
 	 * @return string Original text if {date_created} isn't found. Otherwise, replaced text.
175 175
 	 */
176
-	public static function replace_date_created( $text, $form = array(), $entry = array(), $url_encode = false, $esc_html = false  ) {
176
+	public static function replace_date_created($text, $form = array(), $entry = array(), $url_encode = false, $esc_html = false) {
177 177
 
178 178
 		// Is there is Date Created merge tag?
179
-		preg_match_all( "/{date_created:?(.*?)(?:\s)?}/ism", $text, $matches, PREG_SET_ORDER );
179
+		preg_match_all("/{date_created:?(.*?)(?:\s)?}/ism", $text, $matches, PREG_SET_ORDER);
180 180
 
181 181
 		// If there are no matches OR the Entry `created_by` isn't set or is 0 (no user)
182
-		if ( empty( $matches ) ) {
182
+		if (empty($matches)) {
183 183
 			return $text;
184 184
 		}
185 185
 
186 186
 		$return = $text;
187 187
 
188
-		$date_created = rgar( $entry, 'date_created' );
189
-		$site_date_format  = get_option( 'date_format' );
188
+		$date_created = rgar($entry, 'date_created');
189
+		$site_date_format = get_option('date_format');
190 190
 
191 191
 		/**
192 192
 		 * Gravity Forms code to adjust date to locally-configured Time Zone
193 193
 		 * @see GFCommon::format_date()
194 194
 		 */
195
-		$entry_gmt_time   = mysql2date( 'G', $date_created );
196
-		$entry_local_timestamp = GFCommon::get_local_timestamp( $entry_gmt_time );
195
+		$entry_gmt_time = mysql2date('G', $date_created);
196
+		$entry_local_timestamp = GFCommon::get_local_timestamp($entry_gmt_time);
197 197
 
198
-		foreach ( $matches as $match ) {
198
+		foreach ($matches as $match) {
199 199
 
200 200
 			$full_tag          = $match[0];
201 201
 			$property          = $match[1];
202 202
 
203 203
 			// Expand all modifiers, skipping escaped colons. str_replace worked better than preg_split( "/(?<!\\):/" )
204
-			$exploded = explode( ':', str_replace( '\:', '|COLON|', $property ) );
204
+			$exploded = explode(':', str_replace('\:', '|COLON|', $property));
205 205
 
206
-			$is_human  = in_array( 'human', $exploded ); // {date_created:human}
207
-			$is_diff  = in_array( 'diff', $exploded ); // {date_created:diff}
208
-			$is_raw = in_array( 'raw', $exploded ); // {date_created:raw}
209
-			$is_timestamp = in_array( 'timestamp', $exploded ); // {date_created:timestamp}
206
+			$is_human = in_array('human', $exploded); // {date_created:human}
207
+			$is_diff  = in_array('diff', $exploded); // {date_created:diff}
208
+			$is_raw = in_array('raw', $exploded); // {date_created:raw}
209
+			$is_timestamp = in_array('timestamp', $exploded); // {date_created:timestamp}
210 210
 
211 211
 			// If {date_created:raw} was specified, don't modify the stored value
212
-			if ( $is_raw ) {
212
+			if ($is_raw) {
213 213
 				$formatted_date = $date_created;
214
-			} elseif( $is_timestamp ) {
214
+			} elseif ($is_timestamp) {
215 215
 				$formatted_date = $entry_local_timestamp;
216
-			} elseif ( $is_diff ) {
216
+			} elseif ($is_diff) {
217 217
 
218 218
 				/* translators: %s is the time (seconds, hours, days, weeks, months, years) since entry was created */
219
-				$relative_format = self::get_format_from_modifiers( $exploded, esc_html__( '%s ago', 'gravityview' ) );
219
+				$relative_format = self::get_format_from_modifiers($exploded, esc_html__('%s ago', 'gravityview'));
220 220
 
221
-				$formatted_date = sprintf( $relative_format, human_time_diff( $entry_gmt_time ) );
221
+				$formatted_date = sprintf($relative_format, human_time_diff($entry_gmt_time));
222 222
 
223 223
 			} else {
224 224
 
225
-				$include_time = in_array( 'time', $exploded );  // {date_created:time}
226
-				$match_date_format = self::get_format_from_modifiers( $exploded, $site_date_format );
225
+				$include_time = in_array('time', $exploded); // {date_created:time}
226
+				$match_date_format = self::get_format_from_modifiers($exploded, $site_date_format);
227 227
 
228
-				$formatted_date = GFCommon::format_date( $date_created, $is_human, $match_date_format, $include_time );
228
+				$formatted_date = GFCommon::format_date($date_created, $is_human, $match_date_format, $include_time);
229 229
 			}
230 230
 
231
-			$return = str_replace( $full_tag, $formatted_date, $return );
231
+			$return = str_replace($full_tag, $formatted_date, $return);
232 232
 		}
233 233
 		
234 234
 		return $return;
@@ -247,16 +247,16 @@  discard block
 block discarded – undo
247 247
 	 *
248 248
 	 * @return string If format is found, the passed format. Otherwise, the backup.
249 249
 	 */
250
-	private static function get_format_from_modifiers( $exploded, $backup = '' ) {
250
+	private static function get_format_from_modifiers($exploded, $backup = '') {
251 251
 
252 252
 		$return = $backup;
253 253
 
254
-		$format_key_index = array_search( 'format', $exploded );
254
+		$format_key_index = array_search('format', $exploded);
255 255
 
256 256
 		// If there's a "format:[php date format string]" date format, grab it
257
-		if ( false !== $format_key_index && isset( $exploded[ $format_key_index + 1 ] ) ) {
257
+		if (false !== $format_key_index && isset($exploded[$format_key_index + 1])) {
258 258
 			// Return escaped colons placeholder
259
-			$return = str_replace( '|COLON|', ':', $exploded[ $format_key_index + 1 ] );
259
+			$return = str_replace('|COLON|', ':', $exploded[$format_key_index + 1]);
260 260
 		}
261 261
 
262 262
 		return $return;
@@ -283,22 +283,22 @@  discard block
 block discarded – undo
283 283
 	 * @param array $entry Entry array
284 284
 	 * @param bool $url_encode Whether to URL-encode output
285 285
 	 */
286
-	public static function replace_get_variables( $text, $form = array(), $entry = array(), $url_encode = false ) {
286
+	public static function replace_get_variables($text, $form = array(), $entry = array(), $url_encode = false) {
287 287
 
288 288
 		// Is there is {get:[xyz]} merge tag?
289
-		preg_match_all( "/{get:(.*?)}/ism", $text, $matches, PREG_SET_ORDER );
289
+		preg_match_all("/{get:(.*?)}/ism", $text, $matches, PREG_SET_ORDER);
290 290
 
291 291
 		// If there are no matches OR the Entry `created_by` isn't set or is 0 (no user)
292
-		if( empty( $matches ) ) {
292
+		if (empty($matches)) {
293 293
 			return $text;
294 294
 		}
295 295
 
296
-		foreach ( $matches as $match ) {
296
+		foreach ($matches as $match) {
297 297
 
298 298
 			$full_tag = $match[0];
299 299
 			$property = $match[1];
300 300
 
301
-			$value = stripslashes_deep( rgget( $property ) );
301
+			$value = stripslashes_deep(rgget($property));
302 302
 
303 303
 			/**
304 304
 			 * @filter `gravityview/merge_tags/get/glue/` Modify the glue used to convert an array of `{get}` values from an array to string
@@ -306,11 +306,11 @@  discard block
 block discarded – undo
306 306
 			 * @param[in,out] string $glue String used to `implode()` $_GET values Default: ', '
307 307
 			 * @param[in] string $property The current name of the $_GET parameter being combined
308 308
 			 */
309
-			$glue = apply_filters( 'gravityview/merge_tags/get/glue/', ', ', $property );
309
+			$glue = apply_filters('gravityview/merge_tags/get/glue/', ', ', $property);
310 310
 
311
-			$value = is_array( $value ) ? implode( $glue, $value ) : $value;
311
+			$value = is_array($value) ? implode($glue, $value) : $value;
312 312
 
313
-			$value = $url_encode ? urlencode( $value ) : $value;
313
+			$value = $url_encode ? urlencode($value) : $value;
314 314
 
315 315
 			/**
316 316
 			 * @filter `gravityview/merge_tags/get/esc_html/{url parameter name}` Disable esc_html() from running on `{get}` merge tag
@@ -320,9 +320,9 @@  discard block
 block discarded – undo
320 320
 			 * @since 1.15
321 321
 			 * @param bool $esc_html Whether to esc_html() the value. Default: `true`
322 322
 			 */
323
-			$esc_html = apply_filters('gravityview/merge_tags/get/esc_html/' . $property, true );
323
+			$esc_html = apply_filters('gravityview/merge_tags/get/esc_html/'.$property, true);
324 324
 
325
-			$value = $esc_html ? esc_html( $value ) : $value;
325
+			$value = $esc_html ? esc_html($value) : $value;
326 326
 
327 327
 			/**
328 328
 			 * @filter `gravityview/merge_tags/get/esc_html/{url parameter name}` Modify the value of the `{get}` replacement before being used
@@ -331,12 +331,12 @@  discard block
 block discarded – undo
331 331
 			 * @param[in] array $form Gravity Forms form array
332 332
 			 * @param[in] array $entry Entry array
333 333
 			 */
334
-			$value = apply_filters('gravityview/merge_tags/get/value/' . $property, $value, $text, $form, $entry );
334
+			$value = apply_filters('gravityview/merge_tags/get/value/'.$property, $value, $text, $form, $entry);
335 335
 
336
-			$text = str_replace( $full_tag, $value, $text );
336
+			$text = str_replace($full_tag, $value, $text);
337 337
 		}
338 338
 
339
-		unset( $value, $glue, $matches );
339
+		unset($value, $glue, $matches);
340 340
 
341 341
 		return $text;
342 342
 	}
@@ -357,41 +357,41 @@  discard block
 block discarded – undo
357 357
 	 *
358 358
 	 * @return string Text, with user variables replaced, if they existed
359 359
 	 */
360
-	private static function replace_user_variables_created_by( $text, $form = array(), $entry = array(), $url_encode = false, $esc_html = false ) {
360
+	private static function replace_user_variables_created_by($text, $form = array(), $entry = array(), $url_encode = false, $esc_html = false) {
361 361
 
362 362
 		// Is there is {created_by:[xyz]} merge tag?
363
-		preg_match_all( "/\{created_by:(.*?)\}/", $text, $matches, PREG_SET_ORDER );
363
+		preg_match_all("/\{created_by:(.*?)\}/", $text, $matches, PREG_SET_ORDER);
364 364
 
365 365
 		// If there are no matches OR the Entry `created_by` isn't set or is 0 (no user)
366
-		if( empty( $matches ) || empty( $entry['created_by'] ) ) {
366
+		if (empty($matches) || empty($entry['created_by'])) {
367 367
 			return $text;
368 368
 		}
369 369
 
370 370
 		// Get the creator of the entry
371
-		$entry_creator = new WP_User( $entry['created_by'] );
371
+		$entry_creator = new WP_User($entry['created_by']);
372 372
 
373
-		foreach ( $matches as $match ) {
373
+		foreach ($matches as $match) {
374 374
 
375 375
 			$full_tag = $match[0];
376 376
 			$property = $match[1];
377 377
 
378
-			switch( $property ) {
378
+			switch ($property) {
379 379
 				/** @since 1.13.2 */
380 380
 				case 'roles':
381
-					$value = implode( ', ', $entry_creator->roles );
381
+					$value = implode(', ', $entry_creator->roles);
382 382
 					break;
383 383
 				default:
384
-					$value = $entry_creator->get( $property );
384
+					$value = $entry_creator->get($property);
385 385
 			}
386 386
 
387
-			$value = $url_encode ? urlencode( $value ) : $value;
387
+			$value = $url_encode ? urlencode($value) : $value;
388 388
 
389
-			$value = $esc_html ? esc_html( $value ) : $value;
389
+			$value = $esc_html ? esc_html($value) : $value;
390 390
 
391
-			$text = str_replace( $full_tag, $value, $text );
391
+			$text = str_replace($full_tag, $value, $text);
392 392
 		}
393 393
 
394
-		unset( $entry_creator );
394
+		unset($entry_creator);
395 395
 
396 396
 		return $text;
397 397
 	}
Please login to merge, or discard this patch.