PluginProbe
wpForo Forum / 3.0.9
wpForo Forum v3.0.9
3.1.5 3.1.4 3.1.2 3.1.1 3.1.0 3.0.9 3.0.8 3.0.7 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.2 All 137 releases
wpforo / admin / listtables / Boards.php

Boards.php in wpForo Forum 3.0.9, at admin/listtables/Boards.php

184 lines 7.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace wpforo\admin\listtables;
4
5 use WP_List_Table;
6
7 require_once( ABSPATH . 'wp-admin/includes/template.php' );
8 require_once( ABSPATH . 'wp-admin/includes/screen.php' );
9 require_once( ABSPATH . 'wp-admin/includes/class-wp-screen.php' );
10 require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
11
12 class Boards extends WP_List_Table {
13 /** ************************************************************************
14 * REQUIRED. Set up a constructor that references the parent constructor. We
15 * use the parent reference to set some default configs.
16 ***************************************************************************/
17 function __construct() {
18 //Set parent defaults
19 parent::__construct( [
20 'singular' => 'board', //singular name of the listed records
21 'plural' => 'boards', //plural name of the listed records
22 'ajax' => false, //does this table support ajax?
23 'screen' => 'wpForoBoards',
24 ] );
25
26 }
27
28 function column_default( $item, $column_name ) {
29 return $item[ $column_name ];
30 }
31
32 function column_pageid( $item ) {
33 return ( (get_post( $item['pageid'] )) ? ( ( $edit_post_link = get_edit_post_link( $item['pageid'] )
34 ) ? '<a href="' . $edit_post_link . '">' . $item['pageid'] . '</a>' : $item['pageid'] ) : '<span style="color: red">' .
35 $item['pageid'] . ' ' .
36 __( 'not found', 'wpforo' ) . '</span>' );
37 }
38
39 function column_status( $item ) {
40 return ( $item['status'] ? '<span style="color: green">' . __( 'YES', 'wpforo' ) . '</span>' : '<span style="color: red">' . __( 'NO', 'wpforo' ) . '</span>' );
41 }
42
43 function column_is_standalone( $item ) {
44 return ( $item['is_standalone'] ? '<span style="color: green">' . __( 'YES', 'wpforo' ) . '</span>' : '<span style="color: red">' . __( 'NO', 'wpforo' ) . '</span>' );
45 }
46
47 /** ************************************************************************
48 * Recommended. This is a custom column method and is responsible for what
49 * is rendered in any column with a name/slug of 'title'. Every time the class
50 * needs to render a column, it first looks for a method named
51 * column_{$column_title} - if it exists, that method is run. If it doesn't
52 * exist, column_default() is called instead.
53 *
54 * This example also illustrates how to implement rollover actions. Actions
55 * should be an associative array formatted as 'slug'=>'link html' - and you
56 * will need to generate the URLs yourself. You could even ensure the links
57 *
58 *
59 * @param array $item A singular item (one full row's worth of data)
60 *
61 * @return string Text to be placed inside the column <td> (movie title only)
62 **************************************************************************@see WP_List_Table::::single_row_columns()
63 */
64 function column_boardid( $item ) {
65 $ehref = admin_url(
66 sprintf(
67 'admin.php?page=%1$s&wpfaction=%2$s&boardid=%3$s',
68 'wpforo-boards',
69 'wpforo_board_save_form',
70 $item['boardid']
71 )
72 );
73 $vhref = wpforo_url( '', $item['slug'] );
74 $shref = rtrim( wpforo_url( 'sitemap.xml', $item['slug'] ), '/' );
75 $rhref = wp_nonce_url(
76 admin_url(
77 sprintf(
78 'admin.php?page=%1$s&wpfaction=%2$s&boardid=%3$s',
79 'wpforo-boards',
80 'board_repair',
81 $item['boardid']
82 )
83 ),
84 'wpforo-board-repair-' . $item['boardid']
85 );
86 $dhref = wp_nonce_url(
87 admin_url(
88 sprintf(
89 'admin.php?page=%1$s&wpfaction=%2$s&boardid=%3$s',
90 'wpforo-boards',
91 'board_delete',
92 $item['boardid']
93 )
94 ),
95 'wpforo-board-delete-' . $item['boardid']
96 );
97 //Build row actions
98 $actions = [
99 'edit' => '<a href="' . $ehref . '">' . __( 'Edit', 'wpforo' ) . '</a>',
100 'view' => '<a href="' . $vhref . '" target="_blank">' . __( 'View', 'wpforo' ) . '</a>',
101 'sitemap' => '<a href="' . $shref . '" target="_blank">' . __( 'Sitemap', 'wpforo' ) . '</a>',
102 'repair' => '<a href="' . $rhref . '">' . __( 'Repair', 'wpforo' ) . '</a>',
103 'delete' => '<a onclick="return confirm(\'' . __( "Are you sure you want to DELETE this board and his data permanently?", 'wpforo' ) . '\');" href="' . $dhref . '">' . __( 'Delete', 'wpforo' ) . '</a>',
104 ];
105 if( ! $item['boardid'] ) unset( $actions['delete'] );
106 if( ! $item['status'] ) unset( $actions['view'] );
107
108 //Return the title contents
109 return sprintf(
110 '%1$s %2$s',
111 /*$1%s*/ $item['boardid'],
112 /*$2%s*/ $this->row_actions( $actions )
113 );
114 }
115
116
117 /** ************************************************************************
118 * REQUIRED! This method dictates the table's columns and titles. This should
119 * return an array where the key is the column slug (and class) and the value
120 * is the column's title text. If you need a checkbox for bulk actions, refer
121 * to the $columns array below.
122 *
123 * The 'cb' column is treated differently than the rest. If including a checkbox
124 * column in your table you must create a column_cb() method. If you don't need
125 * to bulk actions or checkboxes, simply leave the 'cb' entry out of your array.
126 *
127 * @return array An associative array containing column information: 'slugs'=>'Visible Titles'
128 **************************************************************************@see WP_List_Table::::single_row_columns()
129 */
130 function get_columns() {
131 return [
132 'boardid' => __( 'boardid', 'wpforo' ),
133 'title' => __( 'title', 'wpforo' ),
134 'slug' => __( 'slug', 'wpforo' ),
135 'pageid' => __( 'pageid', 'wpforo' ),
136 'locale' => __( 'locale', 'wpforo' ),
137 'is_standalone' => __( 'is standalone', 'wpforo' ),
138 'status' => __( 'enabled', 'wpforo' ),
139 ];
140 }
141
142 /** ************************************************************************
143 * REQUIRED! This is where you prepare your data for display. This method will
144 * usually be used to query the database, sort and filter the data, and generally
145 * get it ready to be displayed. At a minimum, we should set $this->items and
146 * $this->set_pagination_args(), although the following properties and methods
147 * are frequently interacted with here...
148 *
149 * @uses $this->_column_headers
150 * @uses $this->items
151 * @uses $this->get_columns()
152 * @uses $this->get_sortable_columns()
153 * @uses $this->get_pagenum()
154 * @uses $this->set_pagination_args()
155 **************************************************************************/
156 function prepare_items() {
157 /**
158 * REQUIRED. Now we need to define our column headers. This includes a complete
159 * array of columns to be displayed (slugs & titles), a list of columns
160 * to keep hidden, and a list of columns that are sortable. Each of these
161 * can be defined in another method (as we've done here) before being
162 * used to build the value for our _column_headers property.
163 */
164 $columns = $this->get_columns();
165 $hidden = [];
166 $sortable = $this->get_sortable_columns();
167
168
169 /**
170 * REQUIRED. Finally, we build an array to be used by the class for column
171 * headers. The $this->_column_headers property takes an array which contains
172 * 3 other arrays. One for all columns, one for hidden columns, and one
173 * for sortable columns.
174 */
175 $this->_column_headers = [ $columns, $hidden, $sortable ];
176
177 /**
178 * REQUIRED. Now we can add our *sorted* data to the items' property, where
179 * it can be used by the rest of the class.
180 */
181 $this->items = WPF()->board->get_boards();
182 }
183 }
184