gravityview /
GravityView
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | namespace GV\Mocks; |
||
| 3 | |||
| 4 | /** |
||
| 5 | * This file contains mock code for deprecated functions. |
||
| 6 | */ |
||
| 7 | |||
| 8 | /** |
||
| 9 | * @see \GravityView_View_Data::add_view |
||
| 10 | * @internal |
||
| 11 | * @since future |
||
| 12 | * |
||
| 13 | * @return array|false The old array data, or false on error. |
||
| 14 | */ |
||
| 15 | function GravityView_View_Data_add_view( $view_id, $atts ) { |
||
| 16 | /** Handle array of IDs. */ |
||
| 17 | 1 | if ( is_array( $view_id ) ) { |
|
| 18 | 1 | foreach ( $view_id as $id ) { |
|
| 19 | 1 | call_user_func( __FUNCTION__, $id, $atts ); |
|
| 20 | } |
||
| 21 | |||
| 22 | 1 | if ( ! gravityview()->request->views->count() ) { |
|
| 23 | 1 | return array(); |
|
| 24 | } |
||
| 25 | |||
| 26 | 1 | return array_combine( |
|
| 27 | array_map( function( $view ) { return $view->ID; }, gravityview()->request->views->all() ), |
||
| 28 | array_map( function( $view ) { return $view->as_data(); }, gravityview()->request->views->all() ) |
||
| 29 | ); |
||
| 30 | } |
||
| 31 | |||
| 32 | /** View has been set already. */ |
||
| 33 | 1 | if ( $view = gravityview()->request->views->get( $view_id ) ) { |
|
| 34 | 1 | do_action( 'gravityview_log_debug', sprintf( 'GravityView_View_Data[add_view] Returning; View #%s already exists.', $view_id ) ); |
|
| 35 | 1 | return $view->as_data(); |
|
| 36 | } |
||
| 37 | |||
| 38 | 1 | $view = \GV\View::by_id( $view_id ); |
|
| 39 | 1 | if ( ! $view ) { |
|
| 40 | 1 | do_action( 'gravityview_log_debug', sprintf( 'GravityView_View_Data[add_view] Returning; View #%s does not exist.', $view_id ) ); |
|
| 41 | 1 | return false; |
|
| 42 | } |
||
| 43 | |||
| 44 | /** Doesn't have a connected form. */ |
||
| 45 | 1 | if ( ! $view->form ) { |
|
| 46 | 1 | do_action( 'gravityview_log_debug', sprintf( 'GravityView_View_Data[add_view] Returning; Post ID #%s does not have a connected form.', $view_id ) ); |
|
| 47 | 1 | return false; |
|
| 48 | } |
||
| 49 | |||
| 50 | /** Update the settings */ |
||
| 51 | 1 | if ( is_array( $atts ) ) { |
|
| 52 | 1 | $view->settings->update( $atts ); |
|
| 53 | } |
||
| 54 | |||
| 55 | 1 | gravityview()->request->views->add( $view ); |
|
| 56 | |||
| 57 | 1 | return $view->as_data(); |
|
|
0 ignored issues
–
show
|
|||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @see \GravityView_frontend::get_view_entries |
||
| 62 | * @internal |
||
| 63 | * @since future |
||
| 64 | * |
||
| 65 | * @return array The old associative array data as returned by |
||
| 66 | * \GravityView_frontend::get_view_entries(), the paging parameters |
||
| 67 | * and a total count of all entries. |
||
| 68 | */ |
||
| 69 | function GravityView_frontend_get_view_entries( $args, $form_id, $parameters, $count ) { |
||
| 70 | 1 | $form = \GV\GF_Form::by_id( $form_id ); |
|
| 71 | |||
| 72 | /** |
||
| 73 | * Kick off all advanced filters. |
||
| 74 | * |
||
| 75 | * Parameters and criteria are pretty much the same thing here, just |
||
| 76 | * different naming, where `$parameters` are the initial parameters |
||
| 77 | * calculated for hte view, and `$criteria` are the filtered ones |
||
| 78 | * retrieved via `GVCommon::calculate_get_entries_criteria`. |
||
| 79 | */ |
||
| 80 | 1 | $criteria = \GVCommon::calculate_get_entries_criteria( $parameters, $form->ID ); |
|
| 81 | |||
| 82 | /** ...and all the (now deprectated) filters that usually follow `gravityview_get_entries` */ |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @deprecated |
||
| 86 | * Do not use this filter anymore. |
||
| 87 | */ |
||
| 88 | 1 | $entries = apply_filters( 'gravityview_before_get_entries', null, $criteria, $parameters, $count ); |
|
| 89 | 1 | if ( ! is_null( $entries ) ) { |
|
| 90 | /** |
||
| 91 | * We've been given an entries result that we can return, |
||
| 92 | * just set the paging and we're good to go. |
||
| 93 | */ |
||
| 94 | 1 | $paging = rgar( $parameters, 'paging' ); |
|
| 95 | } else { |
||
| 96 | 1 | $entries = $form->entries |
|
| 97 | 1 | ->filter( \GV\GF_Entry_Filter::from_search_criteria( $criteria['search_criteria'] ) ) |
|
| 98 | 1 | ->offset( $args['offset'] ) |
|
| 99 | 1 | ->limit( $criteria['paging']['page_size'] ) |
|
| 100 | 1 | ->page( ( ( $criteria['paging']['offset'] - $args['offset'] ) / $criteria['paging']['page_size'] ) + 1 ); |
|
| 101 | 1 | if ( ! empty( $criteria['sorting'] ) ) { |
|
| 102 | 1 | $field = new \GV\Field(); |
|
| 103 | 1 | $field->ID = $criteria['sorting']['key']; |
|
| 104 | 1 | $direction = strtolower( $criteria['sorting']['direction'] ) == 'asc' ? \GV\Entry_Sort::ASC : \GV\Entry_Sort::DESC; |
|
| 105 | 1 | $mode = $criteria['sorting']['is_numeric'] ? \GV\Entry_Sort::NUMERIC : \GV\Entry_Sort::ALPHA; |
|
| 106 | 1 | $entries = $entries->sort( new \GV\Entry_Sort( $field, $direction, $mode ) ); |
|
| 107 | } |
||
| 108 | |||
| 109 | /** Set paging, count and unwrap the entries. */ |
||
| 110 | $paging = array( |
||
| 111 | 1 | 'offset' => ( $entries->current_page - 1 ) * $entries->limit, |
|
| 112 | 1 | 'page_size' => $entries->limit, |
|
| 113 | ); |
||
| 114 | 1 | $count = $entries->total(); |
|
| 115 | $entries = array_map( function( $e ) { return $e->as_entry(); }, $entries->all() ); |
||
| 116 | } |
||
| 117 | |||
| 118 | /** Just one more filter, for compatibility's sake! */ |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @deprecated |
||
| 122 | * Do not use this filter anymore. |
||
| 123 | */ |
||
| 124 | 1 | $entries = apply_filters( 'gravityview_entries', $entries, $criteria, $parameters, $count ); |
|
| 125 | |||
| 126 | 1 | return array( $entries, $paging, $count ); |
|
| 127 | } |
||
| 128 | |||
| 129 | /** Add some global fix for field capability discrepancies. */ |
||
| 130 | add_filter( 'gravityview/configuration/fields', function( $fields ) { |
||
| 131 | 3 | if ( empty( $fields ) ) { |
|
| 132 | return $fields; |
||
| 133 | } |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Each view field is saved in a weird capability state by default. |
||
| 137 | * |
||
| 138 | * With loggedin set to false, but a capability of 'read' it introduces |
||
| 139 | * some logical issues and is not robust. Fix this behavior throughout |
||
| 140 | * core by making sure capability is '' if log in is not required. |
||
| 141 | * |
||
| 142 | * Perhaps in the UI a fix would be to unite the two fields (as our new |
||
| 143 | * \GV\Field class already does) into one dropdown: |
||
| 144 | * |
||
| 145 | * Anyone, Logged In Only, ... etc. etc. |
||
| 146 | * |
||
| 147 | * The two "settings" should be as tightly coupled as possible to avoid |
||
| 148 | * split logic scenarios. Uniting them into one field is the way to go. |
||
| 149 | */ |
||
| 150 | |||
| 151 | 3 | foreach ( $fields as $position => &$_fields ) { |
|
| 152 | |||
| 153 | 3 | if ( empty( $_fields ) ) { |
|
| 154 | continue; |
||
| 155 | } |
||
| 156 | |||
| 157 | 3 | foreach ( $_fields as $uid => &$_field ) { |
|
| 158 | 3 | if ( ! isset( $_field['only_loggedin'] ) ) { |
|
| 159 | continue; |
||
| 160 | } |
||
| 161 | /** If we do not require login, we don't require a cap. */ |
||
| 162 | 3 | $_field['only_loggedin'] != '1' && ( $_field['only_loggedin_cap'] = '' ); |
|
| 163 | } |
||
| 164 | } |
||
| 165 | 3 | return $fields; |
|
| 166 | } ); |
||
| 167 |
This method has been deprecated.