|
@@ -125,7 +125,7 @@ discard block |
|
|
block discarded – undo |
|
125
|
125
|
$supports = array( 'title', 'revisions' ); |
|
126
|
126
|
|
|
127
|
127
|
if ( $is_hierarchical ) { |
|
128
|
|
- $supports[] = 'page-attributes'; |
|
|
128
|
+ $supports[ ] = 'page-attributes'; |
|
129
|
129
|
} |
|
130
|
130
|
|
|
131
|
131
|
/** |
|
@@ -227,11 +227,11 @@ discard block |
|
|
block discarded – undo |
|
227
|
227
|
$rule = array( sprintf( '%s/([^/]+)/csv/?', $slug ), 'index.php?gravityview=$matches[1]&csv=1', 'top' ); |
|
228
|
228
|
|
|
229
|
229
|
add_filter( 'query_vars', function( $query_vars ) { |
|
230
|
|
- $query_vars[] = 'csv'; |
|
|
230
|
+ $query_vars[ ] = 'csv'; |
|
231
|
231
|
return $query_vars; |
|
232
|
232
|
} ); |
|
233
|
233
|
|
|
234
|
|
- if ( ! isset( $wp_rewrite->extra_rules_top[ $rule[0] ] ) ) { |
|
|
234
|
+ if ( ! isset( $wp_rewrite->extra_rules_top[ $rule[ 0 ] ] ) ) { |
|
235
|
235
|
call_user_func_array( 'add_rewrite_rule', $rule ); |
|
236
|
236
|
} |
|
237
|
237
|
} |
|
@@ -300,13 +300,13 @@ discard block |
|
|
block discarded – undo |
|
300
|
300
|
return $content; |
|
301
|
301
|
} |
|
302
|
302
|
|
|
303
|
|
- $is_admin_and_can_view = $view->settings->get( 'admin_show_all_statuses' ) && \GVCommon::has_cap('gravityview_moderate_entries', $view->ID ); |
|
|
303
|
+ $is_admin_and_can_view = $view->settings->get( 'admin_show_all_statuses' ) && \GVCommon::has_cap( 'gravityview_moderate_entries', $view->ID ); |
|
304
|
304
|
|
|
305
|
305
|
/** |
|
306
|
306
|
* Editing a single entry. |
|
307
|
307
|
*/ |
|
308
|
308
|
if ( $entry = $request->is_edit_entry( $view->form ? $view->form->ID : 0 ) ) { |
|
309
|
|
- if ( $entry['status'] != 'active' ) { |
|
|
309
|
+ if ( $entry[ 'status' ] != 'active' ) { |
|
310
|
310
|
gravityview()->log->notice( 'Entry ID #{entry_id} is not active', array( 'entry_id' => $entry->ID ) ); |
|
311
|
311
|
return __( 'You are not allowed to view this content.', 'gravityview' ); |
|
312
|
312
|
} |
|
@@ -317,7 +317,7 @@ discard block |
|
|
block discarded – undo |
|
317
|
317
|
} |
|
318
|
318
|
|
|
319
|
319
|
if ( $view->settings->get( 'show_only_approved' ) && ! $is_admin_and_can_view ) { |
|
320
|
|
- if ( ! \GravityView_Entry_Approval_Status::is_approved( gform_get_meta( $entry->ID, \GravityView_Entry_Approval::meta_key ) ) ) { |
|
|
320
|
+ if ( ! \GravityView_Entry_Approval_Status::is_approved( gform_get_meta( $entry->ID, \GravityView_Entry_Approval::meta_key ) ) ) { |
|
321
|
321
|
gravityview()->log->error( 'Entry ID #{entry_id} is not approved for viewing', array( 'entry_id' => $entry->ID ) ); |
|
322
|
322
|
return __( 'You are not allowed to view this content.', 'gravityview' ); |
|
323
|
323
|
} |
|
@@ -340,7 +340,7 @@ discard block |
|
|
block discarded – undo |
|
340
|
340
|
|
|
341
|
341
|
foreach ( $entryset as $e ) { |
|
342
|
342
|
|
|
343
|
|
- if ( 'active' !== $e['status'] ) { |
|
|
343
|
+ if ( 'active' !== $e[ 'status' ] ) { |
|
344
|
344
|
gravityview()->log->notice( 'Entry ID #{entry_id} is not active', array( 'entry_id' => $e->ID ) ); |
|
345
|
345
|
return __( 'You are not allowed to view this content.', 'gravityview' ); |
|
346
|
346
|
} |
|
@@ -351,7 +351,7 @@ discard block |
|
|
block discarded – undo |
|
351
|
351
|
} |
|
352
|
352
|
|
|
353
|
353
|
if ( $show_only_approved && ! $is_admin_and_can_view ) { |
|
354
|
|
- if ( ! \GravityView_Entry_Approval_Status::is_approved( gform_get_meta( $e->ID, \GravityView_Entry_Approval::meta_key ) ) ) { |
|
|
354
|
+ if ( ! \GravityView_Entry_Approval_Status::is_approved( gform_get_meta( $e->ID, \GravityView_Entry_Approval::meta_key ) ) ) { |
|
355
|
355
|
gravityview()->log->error( 'Entry ID #{entry_id} is not approved for viewing', array( 'entry_id' => $e->ID ) ); |
|
356
|
356
|
return __( 'You are not allowed to view this content.', 'gravityview' ); |
|
357
|
357
|
} |
|
@@ -526,7 +526,7 @@ discard block |
|
|
block discarded – undo |
|
526
|
526
|
$join_column = is_numeric( $join_column ) ? GF_Field::by_id( $join, $join_column ) : Internal_Field::by_id( $join_column ); |
|
527
|
527
|
$join_on_column = is_numeric( $join_on_column ) ? GF_Field::by_id( $join_on, $join_on_column ) : Internal_Field::by_id( $join_on_column ); |
|
528
|
528
|
|
|
529
|
|
- $joins [] = new Join( $join, $join_column, $join_on, $join_on_column ); |
|
|
529
|
+ $joins [ ] = new Join( $join, $join_column, $join_on, $join_on_column ); |
|
530
|
530
|
} |
|
531
|
531
|
|
|
532
|
532
|
return $joins; |
|
@@ -621,13 +621,13 @@ discard block |
|
|
block discarded – undo |
|
621
|
621
|
} |
|
622
|
622
|
|
|
623
|
623
|
foreach ( $_fields as $field ) { |
|
624
|
|
- if ( ! empty( $field['unions'] ) ) { |
|
625
|
|
- foreach ( $field['unions'] as $form_id => $field_id ) { |
|
|
624
|
+ if ( ! empty( $field[ 'unions' ] ) ) { |
|
|
625
|
+ foreach ( $field[ 'unions' ] as $form_id => $field_id ) { |
|
626
|
626
|
if ( ! isset( $unions[ $form_id ] ) ) { |
|
627
|
627
|
$unions[ $form_id ] = array(); |
|
628
|
628
|
} |
|
629
|
629
|
|
|
630
|
|
- $unions[ $form_id ][ $field['id'] ] = |
|
|
630
|
+ $unions[ $form_id ][ $field[ 'id' ] ] = |
|
631
|
631
|
is_numeric( $field_id ) ? \GV\GF_Field::by_id( \GV\GF_Form::by_id( $form_id ), $field_id ) : \GV\Internal_Field::by_id( $field_id ); |
|
632
|
632
|
} |
|
633
|
633
|
} |
|
@@ -676,7 +676,7 @@ discard block |
|
|
block discarded – undo |
|
676
|
676
|
if ( ! $view->form ) { |
|
677
|
677
|
gravityview()->log->error( 'View #{view_id} tried attaching non-existent Form #{form_id} to it.', array( |
|
678
|
678
|
'view_id' => $view->ID, |
|
679
|
|
- 'form_id' => $view->_gravityview_form_id ? : 0, |
|
|
679
|
+ 'form_id' => $view->_gravityview_form_id ?: 0, |
|
680
|
680
|
) ); |
|
681
|
681
|
} |
|
682
|
682
|
|
|
@@ -911,43 +911,42 @@ discard block |
|
|
block discarded – undo |
|
911
|
911
|
* @todo: Stop using _frontend and use something like $request->get_search_criteria() instead |
|
912
|
912
|
*/ |
|
913
|
913
|
$parameters = \GravityView_frontend::get_view_entries_parameters( $this->settings->as_atts(), $this->form->ID ); |
|
914
|
|
- $parameters['context_view_id'] = $this->ID; |
|
|
914
|
+ $parameters[ 'context_view_id' ] = $this->ID; |
|
915
|
915
|
$parameters = \GVCommon::calculate_get_entries_criteria( $parameters, $this->form->ID ); |
|
916
|
916
|
|
|
917
|
917
|
if ( $request instanceof REST\Request ) { |
|
918
|
918
|
$atts = $this->settings->as_atts(); |
|
919
|
919
|
$paging_parameters = wp_parse_args( $request->get_paging(), array( |
|
920
|
|
- 'paging' => array( 'page_size' => $atts['page_size'] ), |
|
|
920
|
+ 'paging' => array( 'page_size' => $atts[ 'page_size' ] ), |
|
921
|
921
|
) ); |
|
922
|
|
- $parameters['paging'] = $paging_parameters['paging']; |
|
|
922
|
+ $parameters[ 'paging' ] = $paging_parameters[ 'paging' ]; |
|
923
|
923
|
} |
|
924
|
924
|
|
|
925
|
|
- $page = Utils::get( $parameters['paging'], 'current_page' ) ? |
|
926
|
|
- : ( ( ( $parameters['paging']['offset'] - $this->settings->get( 'offset' ) ) / $parameters['paging']['page_size'] ) + 1 ); |
|
|
925
|
+ $page = Utils::get( $parameters[ 'paging' ], 'current_page' ) ?: ( ( ( $parameters[ 'paging' ][ 'offset' ] - $this->settings->get( 'offset' ) ) / $parameters[ 'paging' ][ 'page_size' ] ) + 1 ); |
|
927
|
926
|
|
|
928
|
927
|
/** |
|
929
|
928
|
* Cleanup duplicate field_filter parameters to simplify the query. |
|
930
|
929
|
*/ |
|
931
|
930
|
$unique_field_filters = array(); |
|
932
|
|
- foreach ( $parameters['search_criteria']['field_filters'] as $key => $filter ) { |
|
|
931
|
+ foreach ( $parameters[ 'search_criteria' ][ 'field_filters' ] as $key => $filter ) { |
|
933
|
932
|
if ( 'mode' === $key ) { |
|
934
|
|
- $unique_field_filters['mode'] = $filter; |
|
|
933
|
+ $unique_field_filters[ 'mode' ] = $filter; |
|
935
|
934
|
} else if ( ! in_array( $filter, $unique_field_filters ) ) { |
|
936
|
|
- $unique_field_filters[] = $filter; |
|
|
935
|
+ $unique_field_filters[ ] = $filter; |
|
937
|
936
|
} |
|
938
|
937
|
} |
|
939
|
|
- $parameters['search_criteria']['field_filters'] = $unique_field_filters; |
|
|
938
|
+ $parameters[ 'search_criteria' ][ 'field_filters' ] = $unique_field_filters; |
|
940
|
939
|
|
|
941
|
|
- if ( ! empty( $parameters['search_criteria']['field_filters'] ) ) { |
|
|
940
|
+ if ( ! empty( $parameters[ 'search_criteria' ][ 'field_filters' ] ) ) { |
|
942
|
941
|
gravityview()->log->notice( 'search_criteria/field_filters is not empty, third-party code may be using legacy search_criteria filters.' ); |
|
943
|
942
|
} |
|
944
|
943
|
|
|
945
|
944
|
if ( gravityview()->plugin->supports( Plugin::FEATURE_GFQUERY ) ) { |
|
946
|
945
|
$query_class = $this->get_query_class(); |
|
947
|
|
- $query = new $query_class( $this->form->ID, $parameters['search_criteria'], $parameters['sorting'] ); |
|
|
946
|
+ $query = new $query_class( $this->form->ID, $parameters[ 'search_criteria' ], $parameters[ 'sorting' ] ); |
|
948
|
947
|
|
|
949
|
|
- $query->limit( $parameters['paging']['page_size'] ) |
|
950
|
|
- ->offset( ( ( $page - 1 ) * $parameters['paging']['page_size'] ) + $this->settings->get( 'offset' ) ); |
|
|
948
|
+ $query->limit( $parameters[ 'paging' ][ 'page_size' ] ) |
|
|
949
|
+ ->offset( ( ( $page - 1 ) * $parameters[ 'paging' ][ 'page_size' ] ) + $this->settings->get( 'offset' ) ); |
|
951
|
950
|
|
|
952
|
951
|
/** |
|
953
|
952
|
* Any joins? |
|
@@ -970,7 +969,7 @@ discard block |
|
|
block discarded – undo |
|
970
|
969
|
|
|
971
|
970
|
$query_parameters = $query->_introspect(); |
|
972
|
971
|
|
|
973
|
|
- $query->where( \GF_Query_Condition::_and( $query_parameters['where'], $condition ) ); |
|
|
972
|
+ $query->where( \GF_Query_Condition::_and( $query_parameters[ 'where' ], $condition ) ); |
|
974
|
973
|
} |
|
975
|
974
|
|
|
976
|
975
|
|
|
@@ -985,7 +984,7 @@ discard block |
|
|
block discarded – undo |
|
985
|
984
|
|
|
986
|
985
|
$query_parameters = $query->_introspect(); |
|
987
|
986
|
|
|
988
|
|
- $query->where( \GF_Query_Condition::_and( $query_parameters['where'], $condition ) ); |
|
|
987
|
+ $query->where( \GF_Query_Condition::_and( $query_parameters[ 'where' ], $condition ) ); |
|
989
|
988
|
} |
|
990
|
989
|
} |
|
991
|
990
|
|
|
@@ -1002,7 +1001,7 @@ discard block |
|
|
block discarded – undo |
|
1002
|
1001
|
$conditions = array(); |
|
1003
|
1002
|
|
|
1004
|
1003
|
foreach ( $condition->expressions as $_condition ) { |
|
1005
|
|
- $conditions[] = $recurse( $_condition, $fields, $recurse ); |
|
|
1004
|
+ $conditions[ ] = $recurse( $_condition, $fields, $recurse ); |
|
1006
|
1005
|
} |
|
1007
|
1006
|
|
|
1008
|
1007
|
return call_user_func_array( |
|
@@ -1028,11 +1027,11 @@ discard block |
|
|
block discarded – undo |
|
1028
|
1027
|
$q = new $query_class( $form_id ); |
|
1029
|
1028
|
|
|
1030
|
1029
|
// Copy the WHERE clauses but substitute the field_ids to the respective ones |
|
1031
|
|
- $q->where( $where_union_substitute( $query_parameters['where'], $fields, $where_union_substitute ) ); |
|
|
1030
|
+ $q->where( $where_union_substitute( $query_parameters[ 'where' ], $fields, $where_union_substitute ) ); |
|
1032
|
1031
|
|
|
1033
|
1032
|
// Copy the ORDER clause and substitute the field_ids to the respective ones |
|
1034
|
1033
|
$orders = array(); |
|
1035
|
|
- foreach ( $query_parameters['order'] as $order ) { |
|
|
1034
|
+ foreach ( $query_parameters[ 'order' ] as $order ) { |
|
1036
|
1035
|
list( $column, $order ) = $order; |
|
1037
|
1036
|
|
|
1038
|
1037
|
if ( ! $column->is_entry_column() && ! $column->is_meta_column() ) { |
|
@@ -1044,15 +1043,15 @@ discard block |
|
|
block discarded – undo |
|
1044
|
1043
|
|
|
1045
|
1044
|
add_filter( 'gf_query_sql', $gf_query_sql_callback = function( $sql ) use ( &$unions_sql ) { |
|
1046
|
1045
|
// Remove SQL_CALC_FOUND_ROWS as it's not needed in UNION clauses |
|
1047
|
|
- $select = 'UNION ALL ' . str_replace( 'SQL_CALC_FOUND_ROWS ', '', $sql['select'] ); |
|
|
1046
|
+ $select = 'UNION ALL ' . str_replace( 'SQL_CALC_FOUND_ROWS ', '', $sql[ 'select' ] ); |
|
1048
|
1047
|
|
|
1049
|
1048
|
// Record the SQL |
|
1050
|
|
- $unions_sql[] = array( |
|
|
1049
|
+ $unions_sql[ ] = array( |
|
1051
|
1050
|
// Remove columns, we'll rebuild them |
|
1052
|
1051
|
'select' => preg_replace( '#DISTINCT (.*)#', 'DISTINCT ', $select ), |
|
1053
|
|
- 'from' => $sql['from'], |
|
1054
|
|
- 'join' => $sql['join'], |
|
1055
|
|
- 'where' => $sql['where'], |
|
|
1052
|
+ 'from' => $sql[ 'from' ], |
|
|
1053
|
+ 'join' => $sql[ 'join' ], |
|
|
1054
|
+ 'where' => $sql[ 'where' ], |
|
1056
|
1055
|
// Remove order and limit |
|
1057
|
1056
|
); |
|
1058
|
1057
|
|
|
@@ -1069,11 +1068,11 @@ discard block |
|
|
block discarded – undo |
|
1069
|
1068
|
|
|
1070
|
1069
|
add_filter( 'gf_query_sql', $gf_query_sql_callback = function( $sql ) use ( $unions_sql ) { |
|
1071
|
1070
|
// Remove SQL_CALC_FOUND_ROWS as it's not needed in UNION clauses |
|
1072
|
|
- $sql['select'] = str_replace( 'SQL_CALC_FOUND_ROWS ', '', $sql['select'] ); |
|
|
1071
|
+ $sql[ 'select' ] = str_replace( 'SQL_CALC_FOUND_ROWS ', '', $sql[ 'select' ] ); |
|
1073
|
1072
|
|
|
1074
|
1073
|
// Remove columns, we'll rebuild them |
|
1075
|
|
- preg_match( '#DISTINCT (`[motc]\d+`.`.*?`)#', $sql['select'], $select_match ); |
|
1076
|
|
- $sql['select'] = preg_replace( '#DISTINCT (.*)#', 'DISTINCT ', $sql['select'] ); |
|
|
1074
|
+ preg_match( '#DISTINCT (`[motc]\d+`.`.*?`)#', $sql[ 'select' ], $select_match ); |
|
|
1075
|
+ $sql[ 'select' ] = preg_replace( '#DISTINCT (.*)#', 'DISTINCT ', $sql[ 'select' ] ); |
|
1077
|
1076
|
|
|
1078
|
1077
|
$unions = array(); |
|
1079
|
1078
|
|
|
@@ -1084,30 +1083,30 @@ discard block |
|
|
block discarded – undo |
|
1084
|
1083
|
}; |
|
1085
|
1084
|
|
|
1086
|
1085
|
// Add all the order columns into the selects, so we can order by the whole union group |
|
1087
|
|
- preg_match_all( '#(`[motc]\d+`.`.*?`)#', $sql['order'], $order_matches ); |
|
|
1086
|
+ preg_match_all( '#(`[motc]\d+`.`.*?`)#', $sql[ 'order' ], $order_matches ); |
|
1088
|
1087
|
|
|
1089
|
1088
|
$columns = array( |
|
1090
|
|
- sprintf( '%s AS %s', $select_match[1], $column_to_alias( $select_match[1] ) ) |
|
|
1089
|
+ sprintf( '%s AS %s', $select_match[ 1 ], $column_to_alias( $select_match[ 1 ] ) ) |
|
1091
|
1090
|
); |
|
1092
|
1091
|
|
|
1093
|
1092
|
foreach ( array_slice( $order_matches, 1 ) as $match ) { |
|
1094
|
|
- $columns[] = sprintf( '%s AS %s', $match[0], $column_to_alias( $match[0] ) ); |
|
|
1093
|
+ $columns[ ] = sprintf( '%s AS %s', $match[ 0 ], $column_to_alias( $match[ 0 ] ) ); |
|
1095
|
1094
|
|
|
1096
|
1095
|
// Rewrite the order columns to the shared aliases |
|
1097
|
|
- $sql['order'] = str_replace( $match[0], $column_to_alias( $match[0] ), $sql['order'] ); |
|
|
1096
|
+ $sql[ 'order' ] = str_replace( $match[ 0 ], $column_to_alias( $match[ 0 ] ), $sql[ 'order' ] ); |
|
1098
|
1097
|
} |
|
1099
|
1098
|
|
|
1100
|
1099
|
$columns = array_unique( $columns ); |
|
1101
|
1100
|
|
|
1102
|
1101
|
// Add the columns to every UNION |
|
1103
|
1102
|
foreach ( $unions_sql as $union_sql ) { |
|
1104
|
|
- $union_sql['select'] .= implode( ', ', $columns ); |
|
1105
|
|
- $unions []= implode( ' ', $union_sql ); |
|
|
1103
|
+ $union_sql[ 'select' ] .= implode( ', ', $columns ); |
|
|
1104
|
+ $unions [ ] = implode( ' ', $union_sql ); |
|
1106
|
1105
|
} |
|
1107
|
1106
|
|
|
1108
|
1107
|
// Add the columns to the main SELECT, but only grab the entry id column |
|
1109
|
|
- $sql['select'] = 'SELECT SQL_CALC_FOUND_ROWS t1_id FROM (' . $sql['select'] . implode( ', ', $columns ); |
|
1110
|
|
- $sql['order'] = implode( ' ', $unions ) . ') AS u ' . $sql['order']; |
|
|
1108
|
+ $sql[ 'select' ] = 'SELECT SQL_CALC_FOUND_ROWS t1_id FROM (' . $sql[ 'select' ] . implode( ', ', $columns ); |
|
|
1109
|
+ $sql[ 'order' ] = implode( ' ', $unions ) . ') AS u ' . $sql[ 'order' ]; |
|
1111
|
1110
|
|
|
1112
|
1111
|
return $sql; |
|
1113
|
1112
|
} ); |
|
@@ -1148,15 +1147,15 @@ discard block |
|
|
block discarded – undo |
|
1148
|
1147
|
} ); |
|
1149
|
1148
|
} else { |
|
1150
|
1149
|
$entries = $this->form->entries |
|
1151
|
|
- ->filter( \GV\GF_Entry_Filter::from_search_criteria( $parameters['search_criteria'] ) ) |
|
|
1150
|
+ ->filter( \GV\GF_Entry_Filter::from_search_criteria( $parameters[ 'search_criteria' ] ) ) |
|
1152
|
1151
|
->offset( $this->settings->get( 'offset' ) ) |
|
1153
|
|
- ->limit( $parameters['paging']['page_size'] ) |
|
|
1152
|
+ ->limit( $parameters[ 'paging' ][ 'page_size' ] ) |
|
1154
|
1153
|
->page( $page ); |
|
1155
|
1154
|
|
|
1156
|
|
- if ( ! empty( $parameters['sorting'] ) && ! empty( $parameters['sorting']['key'] ) ) { |
|
|
1155
|
+ if ( ! empty( $parameters[ 'sorting' ] ) && ! empty( $parameters[ 'sorting' ][ 'key' ] ) ) { |
|
1157
|
1156
|
$field = new \GV\Field(); |
|
1158
|
|
- $field->ID = $parameters['sorting']['key']; |
|
1159
|
|
- $direction = strtolower( $parameters['sorting']['direction'] ) == 'asc' ? \GV\Entry_Sort::ASC : \GV\Entry_Sort::DESC; |
|
|
1157
|
+ $field->ID = $parameters[ 'sorting' ][ 'key' ]; |
|
|
1158
|
+ $direction = strtolower( $parameters[ 'sorting' ][ 'direction' ] ) == 'asc' ? \GV\Entry_Sort::ASC : \GV\Entry_Sort::DESC; |
|
1160
|
1159
|
$entries = $entries->sort( new \GV\Entry_Sort( $field, $direction ) ); |
|
1161
|
1160
|
} |
|
1162
|
1161
|
} |