]> _ Git - couzy.git/blob
34b532a06eaeb67f2306e973c207328b9431354a
[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' => '<a href="' . $edit_link . '">' . __( 'Edit', 'contact-form-7' ) . '</a>' );
105
106                 if ( current_user_can( 'wpcf7_edit_contact_form', $item->id() ) ) {
107                         $copy_link = wp_nonce_url(
108                                 add_query_arg( array( 'action' => 'copy' ), $url ),
109                                 'wpcf7-copy-contact-form_' . absint( $item->id() ) );
110
111                         $actions = array_merge( $actions, array(
112                                 'copy' => '<a href="' . $copy_link . '">' . __( 'Copy', 'contact-form-7' ) . '</a>' ) );
113                 }
114
115                 $a = sprintf( '<a class="row-title" href="%1$s" title="%2$s">%3$s</a>',
116                         $edit_link,
117                         esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;', 'contact-form-7' ),
118                                 $item->title() ) ),
119                         esc_html( $item->title() ) );
120
121                 return '<strong>' . $a . '</strong> ' . $this->row_actions( $actions );
122     }
123
124         function column_author( $item ) {
125                 $post = get_post( $item->id() );
126
127                 if ( ! $post )
128                         return;
129
130                 $author = get_userdata( $post->post_author );
131
132                 return esc_html( $author->display_name );
133     }
134
135         function column_shortcode( $item ) {
136                 $shortcodes = array(
137                         sprintf( '[contact-form-7 id="%1$d" title="%2$s"]',
138                                 $item->id(), $item->title() ) );
139
140                 $output = '';
141
142                 foreach ( $shortcodes as $shortcode ) {
143                         $output .= "\n" . '<input type="text"'
144                                 . ' onfocus="this.select();" readonly="readonly"'
145                                 . ' value="' . esc_attr( $shortcode ) . '"'
146                                 . ' class="shortcode-in-list-table wp-ui-text-highlight code" />';
147                 }
148
149                 return trim( $output );
150         }
151
152         function column_date( $item ) {
153                 $post = get_post( $item->id() );
154
155                 if ( ! $post )
156                         return;
157
158                 $t_time = mysql2date( __( 'Y/m/d g:i:s A', 'contact-form-7' ), $post->post_date, true );
159                 $m_time = $post->post_date;
160                 $time = mysql2date( 'G', $post->post_date ) - get_option( 'gmt_offset' ) * 3600;
161
162                 $time_diff = time() - $time;
163
164                 if ( $time_diff > 0 && $time_diff < 24*60*60 )
165                         $h_time = sprintf( __( '%s ago', 'contact-form-7' ), human_time_diff( $time ) );
166                 else
167                         $h_time = mysql2date( __( 'Y/m/d', 'contact-form-7' ), $m_time );
168
169                 return '<abbr title="' . $t_time . '">' . $h_time . '</abbr>';
170     }
171 }
172
173 ?>