]> _ Git - couzy.git/blob
ee92f8c612a616ceb05aff288c1bfe349ca31912
[couzy.git] /
1 <?php
2
3 if ( ! class_exists( 'WP_List_Table' ) )
4         require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
5
6 class WPCF7_Contact_Form_List_Table extends WP_List_Table {
7
8         public static function define_columns() {
9                 $columns = array(
10                         'cb' => '<input type="checkbox" />',
11                         'title' => __( 'Title', 'contact-form-7' ),
12                         'shortcode' => __( 'Shortcode', 'contact-form-7' ),
13                         'author' => __( 'Author', 'contact-form-7' ),
14                         'date' => __( 'Date', 'contact-form-7' ) );
15
16                 return $columns;
17         }
18
19         function __construct() {
20                 parent::__construct( array(
21                         'singular' => 'post',
22                         'plural' => 'posts',
23                         'ajax' => false ) );
24         }
25
26         function prepare_items() {
27                 $current_screen = get_current_screen();
28                 $per_page = $this->get_items_per_page( 'cfseven_contact_forms_per_page' );
29
30                 $this->_column_headers = $this->get_column_info();
31
32                 $args = array(
33                         'posts_per_page' => $per_page,
34                         'orderby' => 'title',
35                         'order' => 'ASC',
36                         'offset' => ( $this->get_pagenum() - 1 ) * $per_page );
37
38                 if ( ! empty( $_REQUEST['s'] ) )
39                         $args['s'] = $_REQUEST['s'];
40
41                 if ( ! empty( $_REQUEST['orderby'] ) ) {
42                         if ( 'title' == $_REQUEST['orderby'] )
43                                 $args['orderby'] = 'title';
44                         elseif ( 'author' == $_REQUEST['orderby'] )
45                                 $args['orderby'] = 'author';
46                         elseif ( 'date' == $_REQUEST['orderby'] )
47                                 $args['orderby'] = 'date';
48                 }
49
50                 if ( ! empty( $_REQUEST['order'] ) ) {
51                         if ( 'asc' == strtolower( $_REQUEST['order'] ) )
52                                 $args['order'] = 'ASC';
53                         elseif ( 'desc' == strtolower( $_REQUEST['order'] ) )
54                                 $args['order'] = 'DESC';
55                 }
56
57                 $this->items = WPCF7_ContactForm::find( $args );
58
59                 $total_items = WPCF7_ContactForm::count();
60                 $total_pages = ceil( $total_items / $per_page );
61
62                 $this->set_pagination_args( array(
63                         'total_items' => $total_items,
64                         'total_pages' => $total_pages,
65                         'per_page' => $per_page ) );
66         }
67
68         function get_columns() {
69                 return get_column_headers( get_current_screen() );
70         }
71
72         function get_sortable_columns() {
73                 $columns = array(
74                         'title' => array( 'title', true ),
75                         'author' => array( 'author', false ),
76                         'date' => array( 'date', false ) );
77
78                 return $columns;
79         }
80
81         function get_bulk_actions() {
82                 $actions = array(
83                         'delete' => __( 'Delete', 'contact-form-7' ) );
84
85                 return $actions;
86         }
87
88         function column_default( $item, $column_name ) {
89                 return '';
90         }
91
92         function column_cb( $item ) {
93                 return sprintf(
94                         '<input type="checkbox" name="%1$s[]" value="%2$s" />',
95                         $this->_args['singular'],
96                         $item->id() );
97         }
98
99         function column_title( $item ) {
100                 $url = admin_url( 'admin.php?page=wpcf7&post=' . absint( $item->id() ) );
101                 $edit_link = add_query_arg( array( 'action' => 'edit' ), $url );
102
103                 $actions = array(
104                         'edit' => sprintf( '<a href="%1$s">%2$s</a>',
105                                 esc_url( $edit_link ),
106                                 esc_html( __( 'Edit', 'contact-form-7' ) ) ) );
107
108                 if ( current_user_can( 'wpcf7_edit_contact_form', $item->id() ) ) {
109                         $copy_link = wp_nonce_url(
110                                 add_query_arg( array( 'action' => 'copy' ), $url ),
111                                 'wpcf7-copy-contact-form_' . absint( $item->id() ) );
112
113                         $actions = array_merge( $actions, array(
114                                 'copy' => sprintf( '<a href="%1$s">%2$s</a>',
115                                         esc_url( $copy_link ),
116                                         esc_html( __( 'Duplicate', 'contact-form-7' ) ) ) ) );
117                 }
118
119                 $a = sprintf( '<a class="row-title" href="%1$s" title="%2$s">%3$s</a>',
120                         esc_url( $edit_link ),
121                         esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;', 'contact-form-7' ),
122                                 $item->title() ) ),
123                         esc_html( $item->title() ) );
124
125                 return '<strong>' . $a . '</strong> ' . $this->row_actions( $actions );
126         }
127
128         function column_author( $item ) {
129                 $post = get_post( $item->id() );
130
131                 if ( ! $post )
132                         return;
133
134                 $author = get_userdata( $post->post_author );
135
136                 return esc_html( $author->display_name );
137         }
138
139         function column_shortcode( $item ) {
140                 $shortcodes = array( $item->shortcode() );
141
142                 $output = '';
143
144                 foreach ( $shortcodes as $shortcode ) {
145                         $output .= "\n" . '<span class="shortcode"><input type="text"'
146                                 . ' onfocus="this.select();" readonly="readonly"'
147                                 . ' value="' . esc_attr( $shortcode ) . '"'
148                                 . ' class="large-text code" /></span>';
149                 }
150
151                 return trim( $output );
152         }
153
154         function column_date( $item ) {
155                 $post = get_post( $item->id() );
156
157                 if ( ! $post )
158                         return;
159
160                 $t_time = mysql2date( __( 'Y/m/d g:i:s A', 'contact-form-7' ), $post->post_date, true );
161                 $m_time = $post->post_date;
162                 $time = mysql2date( 'G', $post->post_date ) - get_option( 'gmt_offset' ) * 3600;
163
164                 $time_diff = time() - $time;
165
166                 if ( $time_diff > 0 && $time_diff < 24*60*60 )
167                         $h_time = sprintf( __( '%s ago', 'contact-form-7' ), human_time_diff( $time ) );
168                 else
169                         $h_time = mysql2date( __( 'Y/m/d', 'contact-form-7' ), $m_time );
170
171                 return '<abbr title="' . $t_time . '">' . $h_time . '</abbr>';
172         }
173 }