Caldera_Forms_Entry_UI

AJAX callbacks for viewing entries.

Defined (1)

The class is defined in the following location(s).

/classes/entry/ui.php  
  1. class Caldera_Forms_Entry_UI { 
  2.  
  3. /** 
  4. * Class instance 
  5. * @since 1.4.0 
  6. * @var \Caldera_Forms_Entry_UI 
  7. */ 
  8. protected static $instance; 
  9.  
  10. /** 
  11. * Get class instance 
  12. * @since 1.4.0 
  13. * @return \Caldera_Forms_Entry_UI 
  14. */ 
  15. public static function get_instance() { 
  16. if( null == self::$instance ) { 
  17. self::$instance = new self(); 
  18.  
  19. return self::$instance; 
  20.  
  21.  
  22. /** 
  23. * Get a single entry viewer via AJAX 
  24. * @since 1.4.0 
  25. * @uses "wp_ajax_get_entry" action 
  26. */ 
  27. public function view_entry() { 
  28. if( isset( $_POST, $_POST[ 'nonce' ], $_POST[ 'entry'], $_POST[ 'form' ] ) ) { 
  29.  
  30. $form = Caldera_Forms_Forms::get_form( strip_tags( $_POST[ 'form' ] ) ); 
  31. if( ! current_user_can( Caldera_Forms::get_manage_cap( 'entry-view', $form ) ) || ! wp_verify_nonce( $_POST[ 'nonce' ], 'cf_view_entry' ) ) { 
  32. wp_send_json_error( $_POST ); 
  33.  
  34. $entry_id = absint( $_POST[ 'entry' ] ); 
  35.  
  36. if( 0 < $entry_id && is_array( $form ) ) { 
  37. $entry = Caldera_Forms::get_entry( $entry_id, $form ); 
  38. if( is_wp_error( $entry ) ) { 
  39. wp_send_json_error( $entry ); 
  40. }else{ 
  41. status_header( 200 ); 
  42. wp_send_json( $entry ); 
  43. }else{ 
  44. wp_send_json_error( $_POST ); 
  45.  
  46.  
  47.  
  48.  
  49. wp_send_json_error( $_POST ); 
  50.  
  51. /** 
  52. * Get entry viewer list via AJAX 
  53. * @since 1.4.0 
  54. * @uses "wp_ajax_browse_entries" action 
  55. */ 
  56. public function view_entries() { 
  57. if( ! isset( $_POST[ 'page' ], $_POST[ 'form' ], $_POST[ 'nonce' ] ) ) { 
  58. wp_send_json_error( $_POST ); 
  59.  
  60. $form = Caldera_Forms_Forms::get_form( strip_tags( $_POST[ 'form' ] ) ); 
  61.  
  62. if( ! current_user_can( Caldera_Forms::get_manage_cap( 'entry-view', $form ) ) || ! wp_verify_nonce( $_POST['nonce' ], 'view_entries' ) ) { 
  63. wp_send_json_error( $_POST ); 
  64.  
  65.  
  66. if ( isset( $_POST[ 'page' ] ) && 0 < $_POST[ 'page' ] ) { 
  67. $page = absint( $_POST[ 'page' ] ); 
  68. }else{ 
  69. $page = 1; 
  70.  
  71. $entry_perpage = get_option( '_caldera_forms_entry_perpage', 20 ); 
  72. if ( isset( $_POST[ 'perpage' ] ) && 0 < $_POST[ 'perpage' ] ) { 
  73. $perpage = absint( (int) $_POST[ 'perpage' ] ); 
  74. if( $entry_perpage != $perpage ) { 
  75. update_option( '_caldera_forms_entry_perpage', $perpage ); 
  76. }else{ 
  77. $perpage = $entry_perpage; 
  78.  
  79. if ( isset( $_POST[ 'status' ] ) ) { 
  80. $status = strip_tags( $_POST[ 'status' ] ); 
  81. }else{ 
  82. $status = 'active'; 
  83.  
  84. $data = Caldera_Forms_Admin::get_entries( $form, $page, $perpage, $status ); 
  85.  
  86. $data['is_' . $status ] = true; 
  87.  
  88. status_header( 200 ); 
  89. wp_send_json( $data ); 
  90.  
  91.  
  92.  
  93. /** 
  94. * Get the entry editor (v1) buttons 
  95. * @since 1.5.0 
  96. * @uses "caldera_forms_entry_actions" 
  97. */ 
  98. public static function get_entry_actions() { 
  99. /** 
  100. * Change allowed entry viewer (v1) buttons 
  101. * @since unknown 
  102. * @params array $buttons 
  103. */ 
  104. $viewer_buttons_array = apply_filters( 'caldera_forms_entry_viewer_buttons', array()); 
  105. $viewer_buttons = null; 
  106. if(!empty($viewer_buttons_array)) { 
  107. $viewer_buttons = array(); 
  108. foreach($viewer_buttons_array as $button) { 
  109.  
  110. if(is_array($button['config'])) { 
  111. $config = $button['label'].'|'.json_encode($button['config']); 
  112. }else{ 
  113. $config = $button['label'].'|'.$button['config']; 
  114. if( isset( $button['class'] ) ) { 
  115. $config .= '|' . $button['class']; 
  116. $viewer_buttons[] = $config; 
  117.  
  118. $viewer_buttons = 'data-modal-buttons=\'' . implode(';', $viewer_buttons) . '\''; 
  119.  
  120. /** 
  121. * Change allowed entry editor (v1) buttons 
  122. * @since unknown 
  123. * @params array $buttons 
  124. */ 
  125. $editor_buttons_array = apply_filters( 'caldera_forms_entry_editor_buttons', array()); 
  126. $editor_buttons = null; 
  127. if(!empty($editor_buttons_array)) { 
  128. $editor_buttons = array(); 
  129. foreach($editor_buttons_array as $button) { 
  130.  
  131. if(is_array($button['config'])) { 
  132. $config = $button['label'].'|'.json_encode($button['config']); 
  133. }else{ 
  134. $config = $button['label'].'|'.$button['config']; 
  135. if( isset( $button['class'] ) ) { 
  136. $config .= '|' . $button['class']; 
  137.  
  138. $editor_buttons[] = $config; 
  139.  
  140. $editor_buttons = 'data-modal-buttons=\'' . implode(';', $editor_buttons) . '\''; 
  141.  
  142. if( current_user_can( 'edit_others_posts' ) ) { 
  143. echo '{{#if ../../is_active}}<button class="hidden button button-small cfajax-trigger edit-entry-btn" id="edit-entry-{{_entry_id}}" data-active-class="current-edit" data-static="true" data-load-class="spinner" ' . $editor_buttons . ' data-modal-element="div" data-group="editentry" data-entry="{{_entry_id}}" data-form="{{../../form}}" data-request="' . esc_url( Caldera_Forms::get_submit_url() ) . '{{../../form}}/{{_entry_id}}/?cf-api={{../../form}}" data-method="get" data-modal="view_entry" data-modal-width="700" data-modal-height="auto" data-modal-title="' . esc_attr__( 'Editing Entry ', 'caldera-forms' ) . ' #{{_entry_id}}" type="button" >' . esc_html__( 'Edit', 'caldera-forms' ) . '</button> {{/if}}'; 
  144.  
  145. echo '{{#if ../../is_active}}<button class="button button-small ajax-trigger view-entry-btn" id="view-entry-{{_entry_id}}" data-active-class="current-view" data-static="true" data-load-class="spinner" ' . $viewer_buttons . ' data-group="viewentry" data-entry="{{_entry_id}}" data-form="{{../../form}}" data-action="get_entry" data-modal="view_entry" data-modal-width="700" data-modal-height="700" data-modal-title="' . esc_attr__('Entry', 'caldera-forms' ) . ' #{{_entry_id}}" data-template="#view-entry-tmpl" type="button" data-nonce="' . wp_create_nonce( 'cf_view_entry' ) . '">' . esc_html__( 'View', 'caldera-forms' ) . '</button> {{/if}}'; 
  146. if( current_user_can( 'delete_others_posts' ) ) { 
  147. echo '<button type="button" class="button button-small ajax-trigger" data-load-class="active" data-panel="{{#if ../../is_trash}}trash{{/if}}{{#if ../../is_active}}active{{/if}}" data-do="{{#if ../../is_trash}}active{{/if}}{{#if ../../is_active}}trash{{/if}}" data-callback="cf_refresh_view" data-form="{{../../form}}" data-active-class="disabled" data-group="row{{_entry_id}}" data-load-element="#entry_row_{{_entry_id}}" data-action="cf_bulk_action" data-items="{{_entry_id}}">{{#if ../../is_trash}}' . __('Restore', 'caldera-forms' ) . '{{/if}}{{#if ../../is_active}}' . esc_html__( 'Trash', 'caldera-forms' ) . '{{/if}}</button>'; 
  148.  
  149.  
  150. /** 
  151. * Filter permissions for entry view or export 
  152. * @since 1.5.0 
  153. * @uses "caldera_forms_manage_cap" 
  154. * @param string $cap A capability. By default "manage_options". 
  155. * @param string $context Context to check in. 
  156. * @param array|null $form Form config if it was passed. 
  157. * @return int|string 
  158. */ 
  159. public static function permissions_filter( $cap, $context, $form ) { 
  160. if( ! is_array( $form ) ) { 
  161. return $cap; 
  162.  
  163. switch( $context ) { 
  164. case 'export' : 
  165. case 'entry-view' : 
  166. if( ! empty( $form[ 'pinned' ] ) ) { 
  167. if( isset( $form[ 'pin_roles' ][ 'access_role' ] ) && is_array($form[ 'pin_roles' ][ 'access_role' ] ) ) { 
  168. $user = wp_get_current_user(); 
  169. foreach( $form[ 'pin_roles' ][ 'access_role' ] as $role => $i ) { 
  170. if( in_array( $role, $user->roles ) ) { 
  171. return $role; 
  172.  
  173. break; 
  174.  
  175.  
  176. return $cap; 
  177.  
  178. public static function is_public( array $form ) { 
  179. return apply_filters( 'caldera_forms_entry_viewer_public', false, $form ); 
  180.  
  181.  
  182.  
  183.  
  184.  
  185.