PluginProbe ʕ •ᴥ•ʔ
Permalink Manager Lite / 2.4.0
Permalink Manager Lite v2.4.0
2.6.0 2.5.5 2.5.4 2.5.3.4 2.2.18 2.2.19.2 2.2.19.3 2.2.19.3.1 2.2.2 2.2.20 2.2.20.1 2.2.20.3 2.2.4 2.2.5 2.2.6 2.2.7.2 2.2.7.3 2.2.7.5 2.2.7.6 2.2.8.4 2.2.8.5 2.2.8.6 2.2.8.7 2.2.8.9 2.2.9.1 2.2.9.2 2.2.9.2.1 2.2.9.3 2.2.9.4 2.2.9.6 2.2.9.7 2.2.9.9 2.3.0 2.3.1.1 2.4.0 2.4.1 2.4.1.2 2.4.1.3 2.4.1.4 2.4.1.5 2.4.1.6 2.4.2 2.4.2.1 2.4.3 2.4.3.1 2.4.3.2 2.4.3.3 2.4.3.4 2.4.4 2.4.4.1 2.4.4.2 2.4.4.3 2.5.0 2.5.1 2.5.1.1 2.5.1.2 2.5.1.3 2.5.1.4 2.5.2 2.5.2.1 2.5.2.2 2.5.2.3 2.5.2.4 2.5.3 2.5.3.1 2.5.3.2 2.5.3.3 trunk 0.2 0.3 0.3.1 0.3.2 0.3.3 0.3.4 0.4 0.4.1 0.4.2 0.4.3 0.4.4 0.4.6 0.4.7 0.4.8 0.4.9 0.5.3 0.5.4 1.0.0 1.0.1 1.0.4 1.1.0 1.1.1 1.1.2 1.11.6.3 2.0.0 2.0.3 2.0.4 2.0.4.3 2.0.5.1 2.0.5.2 2.0.5.3 2.0.5.3.1 2.0.5.4 2.0.5.4a 2.0.5.5 2.0.5.6 2.0.5.6.1 2.0.5.7 2.0.5.9a 2.0.6.2.1 2.0.6.2a 2.0.6.3 2.1.0 2.1.1 2.1.2.4 2.2.0 2.2.1.1 2.2.1.2 2.2.11 2.2.12 2.2.13.1 2.2.14 2.2.15.1 2.2.16 2.2.17
permalink-manager / includes / views / permalink-manager-uri-editor-post.php
permalink-manager / includes / views Last commit date
permalink-manager-debug.php 3 years ago permalink-manager-permastructs.php 3 years ago permalink-manager-settings.php 3 years ago permalink-manager-tools.php 3 years ago permalink-manager-uri-editor-post.php 3 years ago permalink-manager-uri-editor.php 3 years ago
permalink-manager-uri-editor-post.php
329 lines
1 <?php
2
3 /**
4 * Use WP_List_Table to display the "Bulk URI Editor" for post items
5 */
6 class Permalink_Manager_URI_Editor_Post extends WP_List_Table {
7
8 public $displayed_post_types, $displayed_post_statuses;
9
10 public function __construct() {
11 global $permalink_manager_options, $active_subsection;
12
13 parent::__construct( array(
14 'singular' => 'slug',
15 'plural' => 'slugs'
16 ) );
17
18 $this->displayed_post_statuses = ( isset( $permalink_manager_options['screen-options']['post_statuses'] ) ) ? "'" . implode( "', '", $permalink_manager_options['screen-options']['post_statuses'] ) . "'" : "'no-post-status'";
19 $this->displayed_post_types = ( $active_subsection && $active_subsection == 'all' ) ? "'" . implode( "', '", $permalink_manager_options['screen-options']['post_types'] ) . "'" : "'{$active_subsection}'";
20 }
21
22 /**
23 * Get the HTML output with the whole WP_List_Table
24 *
25 * @return string
26 */
27 public function display_admin_section() {
28 $output = "<form id=\"permalinks-post-types-table\" class=\"slugs-table\" method=\"post\">";
29 $output .= wp_nonce_field( 'permalink-manager', 'uri_editor' );
30 $output .= Permalink_Manager_Admin_Functions::generate_option_field( 'pm_session_id', array( 'value' => uniqid(), 'type' => 'hidden' ) );
31
32 // Bypass
33 ob_start();
34
35 $this->prepare_items();
36 $this->display();
37 $output .= ob_get_contents();
38
39 ob_end_clean();
40
41 $output .= "</form>";
42
43 return $output;
44 }
45
46 /**
47 * Return an array of classes to be used in the HTML table
48 *
49 * @return array
50 */
51 function get_table_classes() {
52 return array( 'widefat', 'striped', $this->_args['plural'] );
53 }
54
55 /**
56 * Add columns to the table
57 *
58 * @return array
59 */
60 public function get_columns() {
61 return apply_filters( 'permalink_manager_uri_editor_columns', array(
62 'item_title' => __( 'Post title', 'permalink-manager' ),
63 'item_uri' => __( 'Full URI & Permalink', 'permalink-manager' )
64 ) );
65 }
66
67 /**
68 * Define sortable columns
69 *
70 * @return array
71 */
72 public function get_sortable_columns() {
73 return array(
74 'item_title' => array( 'post_title', false )
75 );
76 }
77
78 /**
79 * Data inside the columns
80 *
81 * @param array $item
82 * @param string $column_name
83 *
84 * @return string
85 */
86 public function column_default( $item, $column_name ) {
87 global $permalink_manager_options;
88
89 $uri = Permalink_Manager_URI_Functions_Post::get_post_uri( $item['ID'], true );
90 $uri = ( ! empty( $permalink_manager_options['general']['decode_uris'] ) ) ? urldecode( $uri ) : $uri;
91
92 $field_args_base = array( 'type' => 'text', 'value' => $uri, 'without_label' => true, 'input_class' => 'custom_uri', 'extra_atts' => "data-element-id=\"{$item['ID']}\"" );
93 $permalink = get_permalink( $item['ID'] );
94 $post_title = sanitize_text_field( $item['post_title'] );
95
96 $post_statuses_array = get_post_statuses();
97 $post_statuses_array['inherit'] = __( 'Inherit (Attachment)', 'permalink-manager' );
98
99 $output = apply_filters( 'permalink_manager_uri_editor_column_content', '', $column_name, get_post( $item['ID'] ) );
100 if ( ! empty( $output ) ) {
101 return $output;
102 }
103
104 switch ( $column_name ) {
105 case 'item_uri':
106 // Get auto-update settings
107 $auto_update_val = get_post_meta( $item['ID'], "auto_update_uri", true );
108 $auto_update_uri = ( ! empty( $auto_update_val ) ) ? $auto_update_val : $permalink_manager_options["general"]["auto_update_uris"];
109
110 // Check if drafts are allowed
111 if ( Permalink_Manager_Helper_Functions::is_draft_excluded( (int) $item['ID'] ) ) {
112 $field_args_base['disabled'] = true;
113 $field_args_base['append_content'] = sprintf( '<p class="small uri_locked">%s %s</p>', '<span class="dashicons dashicons-lock"></span>', __( 'URI Editor disabled due to "Exclude drafts & pending posts" setting and the post status.', 'permalink-manager' ) );
114 } else if ( $auto_update_uri == 1 ) {
115 $field_args_base['disabled'] = true;
116 $field_args_base['append_content'] = sprintf( '<p class="small uri_locked">%s %s</p>', '<span class="dashicons dashicons-lock"></span>', __( 'The above permalink will be automatically updated and is locked for editing.', 'permalink-manager' ) );
117 } else if ( $auto_update_uri == 2 ) {
118 $field_args_base['disabled'] = true;
119 $field_args_base['append_content'] = sprintf( '<p class="small uri_locked">%s %s</p>', '<span class="dashicons dashicons-lock"></span>', __( 'URI Editor disabled due to "URI update mode" setting.', 'permalink-manager' ) );
120 }
121
122 $output = '<div class="custom_uri_container">';
123 $output .= Permalink_Manager_Admin_Functions::generate_option_field( "uri[{$item['ID']}]", $field_args_base );
124 $output .= "<span class=\"duplicated_uri_alert\"></span>";
125 $output .= sprintf( "<a class=\"small post_permalink\" href=\"%s\" target=\"_blank\"><span class=\"dashicons dashicons-admin-links\"></span> %s</a>", $permalink, urldecode( $permalink ) );
126 $output .= '</div>';
127
128 return $output;
129
130 case 'item_title':
131 $output = $post_title;
132 $output .= '<div class="extra-info small">';
133 $output .= sprintf( "<span><strong>%s:</strong> %s</span>", __( "Slug", "permalink-manager" ), urldecode( $item['post_name'] ) );
134 $output .= sprintf( " | <span><strong>%s:</strong> {$post_statuses_array[$item["post_status"]]}</span>", __( "Post status", "permalink-manager" ) );
135 $output .= apply_filters( 'permalink_manager_uri_editor_extra_info', '', $column_name, get_post( $item['ID'] ) );
136 $output .= '</div>';
137
138 $output .= '<div class="row-actions">';
139 $output .= sprintf( "<span class=\"edit\"><a href=\"%s/wp-admin/post.php?post={$item['ID']}&amp;action=edit\" title=\"%s\">%s</a> | </span>", get_option( 'home' ), __( 'Edit', 'permalink-manager' ), __( 'Edit', 'permalink-manager' ) );
140 $output .= '<span class="view"><a target="_blank" href="' . $permalink . '" title="' . __( 'View', 'permalink-manager' ) . ' ' . $post_title . '" rel="permalink">' . __( 'View', 'permalink-manager' ) . '</a> | </span>';
141 $output .= '<span class="id">#' . $item['ID'] . '</span>';
142 $output .= '</div>';
143
144 return $output;
145
146 default:
147 return $item[ $column_name ];
148 }
149 }
150
151 /**
152 * The button that allows to save updated slugs
153 */
154 function extra_tablenav( $which ) {
155 global $wpdb, $active_section, $active_subsection;
156
157 $button_top = __( 'Save all the URIs below', 'permalink-manager' );
158 $button_bottom = __( 'Save all the URIs above', 'permalink-manager' );
159
160 $html = "<div class=\"alignleft actions\">";
161 $html .= get_submit_button( ${"button_$which"}, 'primary alignleft', "update_all_slugs[{$which}]", false, array( 'id' => 'doaction', 'value' => 'update_all_slugs' ) );
162
163 if ( $which == "top" ) {
164 $html .= '<div class="alignright">';
165 $html .= $this->search_box( __( 'Search', 'permalink-manager' ), 'search-input' );
166 $html .= '</div>';
167
168 // Filter by date
169 $months = $wpdb->get_results( "SELECT DISTINCT month(post_date) AS m, year(post_date) AS y FROM {$wpdb->posts} WHERE post_status IN ($this->displayed_post_statuses) AND post_type IN ($this->displayed_post_types) ORDER BY post_date DESC", ARRAY_A );
170 if ( $months ) {
171 $month_key = 'month';
172 $screen = get_current_screen();
173 $current_url = add_query_arg( array(
174 'page' => PERMALINK_MANAGER_PLUGIN_SLUG,
175 'section' => $active_section,
176 'subsection' => $active_subsection
177 ), admin_url( $screen->parent_file ) );
178
179 $html .= "<div id=\"months-filter\" class=\"alignright hide-if-no-js\" data-filter-url=\"{$current_url}\">";
180 $html .= "<select id=\"months-filter-select\" name=\"{$month_key}\">";
181 $html .= sprintf( "<option value=\"\">%s</option>", __( "All dates", "permalink-manager" ) );
182 foreach ( $months as $month ) {
183 $month_raw = "{$month['y']}-{$month['m']}";
184 $month_human_name = date_i18n( "F Y", strtotime( $month_raw ) );
185
186 $selected = ( ! empty( $_REQUEST[ $month_key ] ) ) ? selected( $_REQUEST[ $month_key ], $month_raw, false ) : "";
187 $html .= "<option value=\"{$month_raw}\" {$selected}>{$month_human_name}</option>";
188 }
189 $html .= "</select>";
190 $html .= get_submit_button( __( "Filter", "permalink-manager" ), 'button', false, false, array( 'id' => 'months-filter-button', 'name' => 'months-filter-button' ) );
191 $html .= "</div>";
192 }
193 }
194 $html .= "</div>";
195
196 echo $html;
197 }
198
199 /**
200 * Display the search input field
201 *
202 * @return string
203 */
204 public function search_box( $text = '', $input_id = '' ) {
205 $search_query = ( ! empty( $_REQUEST['s'] ) ) ? esc_attr( $_REQUEST['s'] ) : "";
206
207 $output = "<p class=\"search-box\">";
208 $output .= "<label class=\"screen-reader-text\" for=\"{$input_id}\">{$text}:</label>";
209 $output .= Permalink_Manager_Admin_Functions::generate_option_field( 's', array( 'value' => $search_query, 'type' => 'search' ) );
210 $output .= get_submit_button( $text, 'button', false, false, array( 'id' => 'search-submit', 'name' => 'search-submit' ) );
211 $output .= "</p>";
212
213 return $output;
214 }
215
216 /**
217 * Prepare the items for the table to process
218 */
219 public function prepare_items() {
220 global $wpdb, $permalink_manager_options;
221
222 $columns = $this->get_columns();
223 $hidden = $this->get_hidden_columns();
224 $sortable = $this->get_sortable_columns();
225 $current_page = $this->get_pagenum();
226
227 // Get query variables
228 $per_page = $permalink_manager_options['screen-options']['per_page'];
229
230 // SQL query parameters
231 $order = ( isset( $_REQUEST['order'] ) && in_array( $_REQUEST['order'], array( 'asc', 'desc' ) ) ) ? sanitize_sql_orderby( $_REQUEST['order'] ) : 'desc';
232 $orderby = ( isset( $_REQUEST['orderby'] ) ) ? sanitize_sql_orderby( $_REQUEST['orderby'] ) : 'ID';
233 $offset = ( $current_page - 1 ) * $per_page;
234 $search_query = ( ! empty( $_REQUEST['s'] ) ) ? esc_sql( $_REQUEST['s'] ) : "";
235
236 // Extra filters
237 $extra_filters = $attachment_support = '';
238 if ( ! empty( $_GET['month'] ) ) {
239 $month = date( "n", strtotime( $_GET['month'] ) );
240 $year = date( "Y", strtotime( $_GET['month'] ) );
241
242 $extra_filters .= "AND month(post_date) = {$month} AND year(post_date) = {$year}";
243 }
244
245 // Support for attachments
246 if ( strpos( $this->displayed_post_types, 'attachment' ) !== false ) {
247 $attachment_support = " OR (post_type = 'attachment')";
248 }
249
250 // Grab posts from database
251 $sql_parts['start'] = "SELECT * FROM {$wpdb->posts} ";
252 if ( $search_query ) {
253 $sql_parts['where'] = "WHERE (LOWER(post_title) LIKE LOWER('%{$search_query}%') ";
254
255 // Search in array with custom URIs
256 $found = Permalink_Manager_Helper_Functions::search_uri( $search_query, 'posts' );
257 if ( $found ) {
258 $sql_parts['where'] .= sprintf( "OR ID IN (%s)", implode( ',', $found ) );
259 }
260 $sql_parts['where'] .= " ) AND ((post_status IN ($this->displayed_post_statuses) AND post_type IN ($this->displayed_post_types)) {$attachment_support}) {$extra_filters} ";
261 } else {
262 $sql_parts['where'] = "WHERE ((post_status IN ($this->displayed_post_statuses) AND post_type IN ($this->displayed_post_types)) {$attachment_support}) {$extra_filters} ";
263 }
264
265 // Do not display excluded posts in Bulk URI Editor
266 $excluded_posts = (array) apply_filters( 'permalink_manager_excluded_post_ids', array() );
267 if ( ! empty( $excluded_posts ) ) {
268 $sql_parts['where'] .= sprintf( "AND ID NOT IN ('%s') ", implode( "', '", $excluded_posts ) );
269 }
270
271 $sql_parts['end'] = "ORDER BY {$orderby} {$order}";
272
273 // Prepare the SQL query
274 $sql_query = implode( "", $sql_parts );
275
276 // Count items
277 $count_query = str_replace( 'SELECT *', 'SELECT COUNT(*)', $sql_query );
278 $total_items = $wpdb->get_var( $count_query );
279
280 // Pagination support
281 $sql_query .= sprintf( " LIMIT %d, %d", $offset, $per_page );
282
283 // Get items
284 $sql_query = apply_filters( 'permalink_manager_filter_uri_editor_query', $sql_query, $this, $sql_parts, $is_taxonomy = false );
285 $all_items = $wpdb->get_results( $sql_query, ARRAY_A );
286
287 // Debug SQL query
288 if ( isset( $_REQUEST['debug_editor_sql'] ) ) {
289 $debug_txt = "<textarea style=\"width:100%;height:300px\">{$sql_query} \n\nOffset: {$offset} \nPage: {$current_page}\nPer page: {$per_page} \nTotal: {$total_items}</textarea>";
290 wp_die( $debug_txt );
291 }
292
293 $this->set_pagination_args( array(
294 'total_items' => $total_items,
295 'per_page' => $per_page
296 ) );
297
298 $this->_column_headers = array( $columns, $hidden, $sortable );
299 $this->items = $all_items;
300 }
301
302 /**
303 * Define hidden columns
304 *
305 * @return array
306 */
307 public function get_hidden_columns() {
308 return array();
309 }
310
311 /**
312 * Sort the data
313 *
314 * @param mixed $a
315 * @param mixed $b
316 *
317 * @return int
318 */
319 private function sort_data( $a, $b ) {
320 // Set defaults
321 $orderby = ( ! empty( $_GET['orderby'] ) ) ? sanitize_sql_orderby( $_GET['orderby'] ) : 'post_title';
322 $order = ( ! empty( $_GET['order'] ) ) ? sanitize_sql_orderby( $_GET['order'] ) : 'asc';
323 $result = strnatcasecmp( $a[ $orderby ], $b[ $orderby ] );
324
325 return ( $order === 'asc' ) ? $result : - $result;
326 }
327
328 }
329