core = $core;
// Initialize layout and column definitions,
$this->setup_columns();
$this->setup_layouts();
// Figure out what the "safe" URL to acccess the current page would be.
// This is used by the bulk action form.
$special_args = array( '_wpnonce', '_wp_http_referer', 'action', 'selected_links' );
$this->neutral_current_url = remove_query_arg( $special_args );
}
/**
* Print the entire link table and associated navigation elements.
*
* @param array $current_filter
* @param string $layout
* @param array $visible_columns
* @param bool $compact
* @return void
*/
function print_table( $current_filter, $layout = 'flexible', $visible_columns = null, $compact = false ) {
$this->current_filter = $current_filter;
$this->page = $current_filter['page'];
$this->per_page = $current_filter['per_page'];
$current_layout = $this->layouts[ $layout ];
if ( empty( $visible_columns ) ) {
$visible_columns = $current_layout;
}
// Only allow columns actually present in this layout.
$visible_columns = array_intersect( $visible_columns, $current_layout );
echo '
';
// Inline editor (hidden by default, JS will move it to the right place).
$this->inline_editor( $visible_columns );
}
/**
* Print the "Bulk Actions" dropdown and navigation links
*
* @param bool $table_compact Whether to use the full or compact view.
* @param string $suffix Optional. Appended to ID and name attributes of the bulk action dropdown.
* @return void
*/
function navigation( $table_compact = false, $suffix = '' ) {
// Display the "Bulk Actions" dropdown.
echo '
';
// Display pagination links.
if ( ! empty( $this->pagination_html ) ) {
echo $this->pagination_html;
}
// Display the view switch (only in the top nav. area).
if ( empty( $suffix ) ) {
?>
';
}
/**
* Initialize the internal list of available table columns.
*
* @return void
*/
function setup_columns() {
$this->columns = array(
'status' => array(
'heading' => __( 'Status', 'broken-link-checker' ),
'content' => array( $this, 'column_status' ),
),
'new-url' => array(
'heading' => __( 'URL', 'broken-link-checker' ),
'content' => array( $this, 'column_new_url' ),
'sortable' => true,
'orderby' => 'url',
),
'used-in' => array(
'heading' => __( 'Source', 'broken-link-checker' ),
'class' => 'column-title',
'content' => array( $this, 'column_used_in' ),
),
'new-link-text' => array(
'heading' => __( 'Link Text', 'broken-link-checker' ),
'content' => array( $this, 'column_new_link_text' ),
'sortable' => true,
'orderby' => 'link_text',
),
'redirect-url' => array(
'heading' => __( 'Redirect URL', 'broken-link-checker' ),
'content' => array( $this, 'column_redirect_url' ),
'sortable' => true,
'orderby' => 'redirect_url',
),
);
}
/**
* Initialize the list of available layouts
*
* @return void
*/
function setup_layouts() {
$this->layouts = array(
'classic' => array( 'used-in', 'new-link-text', 'new-url' ),
'flexible' => array( 'new-url', 'status', 'new-link-text', 'redirect-url', 'used-in' ),
);
}
/**
* Get a list of columns available in a specific table layout.
*
* @param string $layout Layout ID.
* @return array Associative array of column data indexed by column ID.
*/
function get_layout_columns( $layout ) {
if ( isset( $this->layouts[ $layout ] ) ) {
$result = array();
foreach ( $this->layouts[ $layout ] as $column_id ) {
if ( isset( $this->columns[ $column_id ] ) ) {
$result[ $column_id ] = $this->columns[ $column_id ];
}
}
return $result;
} else {
return null;
}
}
/**
* Pre-generate some HTML fragments used for both the top and bottom navigation/bulk action boxes.
*
* @return void
*/
function prepare_nav_html() {
//Generate an ', $value, $name );
}
$this->bulk_actions_html = $bulk_actions_html;
// Pagination links can also be pre-generated.
// WP has a built-in function for pagination :).
$page_links = paginate_links(
array(
'base' => add_query_arg( 'paged', '%#%' ),
'format' => '',
'prev_text' => __( '«' ),
'next_text' => __( '»' ),
'total' => $this->current_filter['max_pages'],
'current' => $this->page,
)
);
if ( $page_links ) {
$this->pagination_html = '
';
}
/**
* Print the contents of the details row for a specific link.
*
* @param blcLink $link
* @return void
*/
public static function details_row_contents( $link ) {
?>
';
printf(
'%s',
esc_attr( __( 'Show more info about this link', 'broken-link-checker' ) ),
_x( 'Details', 'link in the "Status" column', 'broken-link-checker' )
);
echo '
';
}
/**
* @param blcLink $link
*/
function column_new_url( $link ) {
?>
url ); ?>
" . __( 'Edit URL', 'broken-link-checker' ) . '';
$actions['delete'] = "" . __( 'Unlink', 'broken-link-checker' ) . '';
if ( $link->broken || $link->warning ) {
$actions['blc-discard-action'] = sprintf(
'%s',
esc_attr( __( 'Remove this link from the list of broken links and mark it as valid', 'broken-link-checker' ) ),
__( 'Not broken', 'broken-link-checker' )
);
}
if ( ! $link->dismissed && ( $link->broken || $link->warning || ( $link->redirect_count > 0 ) ) ) {
$actions['blc-dismiss-action'] = sprintf(
'%s',
esc_attr( __( 'Hide this link and do not report it again unless its status changes', 'broken-link-checker' ) ),
__( 'Dismiss', 'broken-link-checker' )
);
} elseif ( $link->dismissed ) {
$actions['blc-undismiss-action'] = sprintf(
'%s',
esc_attr( __( 'Undismiss this link', 'broken-link-checker' ) ),
__( 'Undismiss', 'broken-link-checker' )
);
}
$actions['blc-recheck-action'] = sprintf(
'%s',
__( 'Recheck', 'broken-link-checker' )
);
if ( $link->redirect_count > 0 && ! empty( $link->final_url ) && ( $link->url != $link->final_url ) ) {
//TODO: Check if at least one instance has an editable URL. Otherwise this won't work.
$actions['blc-deredirect-action'] = sprintf(
'%s',
__( 'Replace this redirect with a direct link', 'broken-link-checker' ),
_x( 'Fix redirect', 'link action; replace one redirect with a direct link', 'broken-link-checker' )
);
}
// Only show the enabled actions.
$conf = blc_get_configuration();
foreach ( $conf->get( 'show_link_actions', $actions ) as $name => $enabled ) {
if ( ! $enabled ) {
unset( $actions[ $name ] );
}
}
// Wrap actions with and separate them with | characters.
// Basically, this emulates the HTML structure that WP uses for post actions under Posts -> All Posts.
$spans = array();
$is_first_action = true;
foreach ( $actions as $name => $html ) {
$spans[] = sprintf(
'%s%s',
esc_attr( $name ),
$is_first_action ? '' : ' | ',
$html
);
$is_first_action = false;
}
echo '