Edit File by line
/home/barbar84/www/wp-conte.../plugins/wordpres.../src/presente...
File: breadcrumbs-presenter.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Presenters;
[2] Fix | Delete
[3] Fix | Delete
use Yoast\WP\SEO\Presentations\Indexable_Presentation;
[4] Fix | Delete
[5] Fix | Delete
/**
[6] Fix | Delete
* Presenter class for the breadcrumbs.
[7] Fix | Delete
*/
[8] Fix | Delete
class Breadcrumbs_Presenter extends Abstract_Indexable_Presenter {
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* The id attribute.
[12] Fix | Delete
*
[13] Fix | Delete
* @var string
[14] Fix | Delete
*/
[15] Fix | Delete
private $id;
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* The class name attribute.
[19] Fix | Delete
*
[20] Fix | Delete
* @var string
[21] Fix | Delete
*/
[22] Fix | Delete
private $class;
[23] Fix | Delete
[24] Fix | Delete
/**
[25] Fix | Delete
* The wrapper element name.
[26] Fix | Delete
*
[27] Fix | Delete
* @var string
[28] Fix | Delete
*/
[29] Fix | Delete
private $wrapper;
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* Separator to use.
[33] Fix | Delete
*
[34] Fix | Delete
* @var string
[35] Fix | Delete
*/
[36] Fix | Delete
private $separator;
[37] Fix | Delete
[38] Fix | Delete
/**
[39] Fix | Delete
* The element.
[40] Fix | Delete
*
[41] Fix | Delete
* @var string
[42] Fix | Delete
*/
[43] Fix | Delete
private $element;
[44] Fix | Delete
[45] Fix | Delete
/**
[46] Fix | Delete
* Presents the breadcrumbs.
[47] Fix | Delete
*
[48] Fix | Delete
* @return string The breadcrumbs HTML.
[49] Fix | Delete
*/
[50] Fix | Delete
public function present() {
[51] Fix | Delete
$breadcrumbs = $this->get();
[52] Fix | Delete
if ( ! \is_array( $breadcrumbs ) || empty( $breadcrumbs ) ) {
[53] Fix | Delete
return '';
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
$links = [];
[57] Fix | Delete
$total = \count( $breadcrumbs );
[58] Fix | Delete
foreach ( $breadcrumbs as $index => $breadcrumb ) {
[59] Fix | Delete
$links[ $index ] = $this->crumb_to_link( $breadcrumb, $index, $total );
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
// Removes any effectively empty links.
[63] Fix | Delete
$links = \array_map( 'trim', $links );
[64] Fix | Delete
$links = \array_filter( $links );
[65] Fix | Delete
$output = \implode( $this->get_separator(), $links );
[66] Fix | Delete
[67] Fix | Delete
if ( empty( $output ) ) {
[68] Fix | Delete
return '';
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
$output = '<' . $this->get_wrapper() . $this->get_id() . $this->get_class() . '>' . $output . '</' . $this->get_wrapper() . '>';
[72] Fix | Delete
$output = $this->filter( $output );
[73] Fix | Delete
[74] Fix | Delete
$prefix = $this->helpers->options->get( 'breadcrumbs-prefix' );
[75] Fix | Delete
if ( $prefix !== '' ) {
[76] Fix | Delete
$output = "\t" . $prefix . "\n" . $output;
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
return $output;
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
/**
[83] Fix | Delete
* Gets the raw value of a presentation.
[84] Fix | Delete
*
[85] Fix | Delete
* @return array The raw value.
[86] Fix | Delete
*/
[87] Fix | Delete
public function get() {
[88] Fix | Delete
return $this->presentation->breadcrumbs;
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
/**
[92] Fix | Delete
* Filters the output.
[93] Fix | Delete
*
[94] Fix | Delete
* @param string $output The HTML output.
[95] Fix | Delete
*
[96] Fix | Delete
* @return string The filtered output.
[97] Fix | Delete
*/
[98] Fix | Delete
protected function filter( $output ) {
[99] Fix | Delete
/**
[100] Fix | Delete
* Filter: 'wpseo_breadcrumb_output' - Allow changing the HTML output of the Yoast SEO breadcrumbs class.
[101] Fix | Delete
*
[102] Fix | Delete
* @param Indexable_Presentation $presentation The presentation of an indexable.
[103] Fix | Delete
*
[104] Fix | Delete
* @api string $output The HTML output.
[105] Fix | Delete
*/
[106] Fix | Delete
return \apply_filters( 'wpseo_breadcrumb_output', $output, $this->presentation );
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
/**
[110] Fix | Delete
* Create a breadcrumb element string.
[111] Fix | Delete
*
[112] Fix | Delete
* @param array $breadcrumb Link info array containing the keys:
[113] Fix | Delete
* 'text' => (string) link text.
[114] Fix | Delete
* 'url' => (string) link url.
[115] Fix | Delete
* (optional) 'title' => (string) link title attribute text.
[116] Fix | Delete
* @param int $index Index for the current breadcrumb.
[117] Fix | Delete
* @param int $total The total number of breadcrumbs.
[118] Fix | Delete
*
[119] Fix | Delete
* @return string The breadcrumb link.
[120] Fix | Delete
*/
[121] Fix | Delete
protected function crumb_to_link( $breadcrumb, $index, $total ) {
[122] Fix | Delete
$link = '';
[123] Fix | Delete
[124] Fix | Delete
if ( ! isset( $breadcrumb['text'] ) || ! \is_string( $breadcrumb['text'] ) || empty( $breadcrumb['text'] ) ) {
[125] Fix | Delete
return $link;
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
$text = \trim( $breadcrumb['text'] );
[129] Fix | Delete
[130] Fix | Delete
if (
[131] Fix | Delete
$index < ( $total - 1 )
[132] Fix | Delete
&& isset( $breadcrumb['url'] )
[133] Fix | Delete
&& \is_string( $breadcrumb['url'] )
[134] Fix | Delete
&& ! empty( $breadcrumb['url'] )
[135] Fix | Delete
) {
[136] Fix | Delete
// If it's not the last element and we have a url.
[137] Fix | Delete
$link .= '<' . $this->get_element() . '>';
[138] Fix | Delete
$title_attr = isset( $breadcrumb['title'] ) ? ' title="' . \esc_attr( $breadcrumb['title'] ) . '"' : '';
[139] Fix | Delete
$link .= '<a href="' . \esc_url( $breadcrumb['url'] ) . '"' . $title_attr . '>' . $text . '</a>';
[140] Fix | Delete
}
[141] Fix | Delete
elseif ( $index === ( $total - 1 ) ) {
[142] Fix | Delete
// If it's the last element.
[143] Fix | Delete
$inner_elm = 'span';
[144] Fix | Delete
if ( $this->helpers->options->get( 'breadcrumbs-boldlast' ) === true ) {
[145] Fix | Delete
$inner_elm = 'strong';
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
$link .= '<' . $inner_elm . ' class="breadcrumb_last" aria-current="page">' . $text . '</' . $inner_elm . '>';
[149] Fix | Delete
// This is the last element, now close all previous elements.
[150] Fix | Delete
while ( $index > 0 ) {
[151] Fix | Delete
$link .= '</' . $this->get_element() . '>';
[152] Fix | Delete
--$index;
[153] Fix | Delete
}
[154] Fix | Delete
}
[155] Fix | Delete
else {
[156] Fix | Delete
// It's not the last element and has no url.
[157] Fix | Delete
$link .= '<span>' . $text . '</span>';
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
/**
[161] Fix | Delete
* Filter: 'wpseo_breadcrumb_single_link' - Allow changing of each link being put out by the Yoast SEO breadcrumbs class.
[162] Fix | Delete
*
[163] Fix | Delete
* @param array $link The link array.
[164] Fix | Delete
*
[165] Fix | Delete
* @api string $link_output The output string.
[166] Fix | Delete
*/
[167] Fix | Delete
return \apply_filters( 'wpseo_breadcrumb_single_link', $link, $breadcrumb );
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
/**
[171] Fix | Delete
* Retrieves HTML ID attribute.
[172] Fix | Delete
*
[173] Fix | Delete
* @return string The id attribute.
[174] Fix | Delete
*/
[175] Fix | Delete
protected function get_id() {
[176] Fix | Delete
if ( ! $this->id ) {
[177] Fix | Delete
/**
[178] Fix | Delete
* Filter: 'wpseo_breadcrumb_output_id' - Allow changing the HTML ID on the Yoast SEO breadcrumbs wrapper element.
[179] Fix | Delete
*
[180] Fix | Delete
* @api string $unsigned ID to add to the wrapper element.
[181] Fix | Delete
*/
[182] Fix | Delete
$this->id = \apply_filters( 'wpseo_breadcrumb_output_id', '' );
[183] Fix | Delete
if ( ! \is_string( $this->id ) ) {
[184] Fix | Delete
return '';
[185] Fix | Delete
}
[186] Fix | Delete
[187] Fix | Delete
if ( $this->id !== '' ) {
[188] Fix | Delete
$this->id = ' id="' . \esc_attr( $this->id ) . '"';
[189] Fix | Delete
}
[190] Fix | Delete
}
[191] Fix | Delete
[192] Fix | Delete
return $this->id;
[193] Fix | Delete
}
[194] Fix | Delete
[195] Fix | Delete
/**
[196] Fix | Delete
* Retrieves HTML Class attribute.
[197] Fix | Delete
*
[198] Fix | Delete
* @return string The class attribute.
[199] Fix | Delete
*/
[200] Fix | Delete
protected function get_class() {
[201] Fix | Delete
if ( ! $this->class ) {
[202] Fix | Delete
/**
[203] Fix | Delete
* Filter: 'wpseo_breadcrumb_output_class' - Allow changing the HTML class on the Yoast SEO breadcrumbs wrapper element.
[204] Fix | Delete
*
[205] Fix | Delete
* @api string $unsigned Class to add to the wrapper element.
[206] Fix | Delete
*/
[207] Fix | Delete
$this->class = \apply_filters( 'wpseo_breadcrumb_output_class', '' );
[208] Fix | Delete
if ( ! \is_string( $this->class ) ) {
[209] Fix | Delete
return '';
[210] Fix | Delete
}
[211] Fix | Delete
[212] Fix | Delete
if ( $this->class !== '' ) {
[213] Fix | Delete
$this->class = ' class="' . \esc_attr( $this->class ) . '"';
[214] Fix | Delete
}
[215] Fix | Delete
}
[216] Fix | Delete
[217] Fix | Delete
return $this->class;
[218] Fix | Delete
}
[219] Fix | Delete
[220] Fix | Delete
/**
[221] Fix | Delete
* Retrieves the wrapper element name.
[222] Fix | Delete
*
[223] Fix | Delete
* @return string The wrapper element name.
[224] Fix | Delete
*/
[225] Fix | Delete
protected function get_wrapper() {
[226] Fix | Delete
if ( ! $this->wrapper ) {
[227] Fix | Delete
$this->wrapper = \apply_filters( 'wpseo_breadcrumb_output_wrapper', 'span' );
[228] Fix | Delete
$this->wrapper = \tag_escape( $this->wrapper );
[229] Fix | Delete
if ( ! \is_string( $this->wrapper ) || $this->wrapper === '' ) {
[230] Fix | Delete
$this->wrapper = 'span';
[231] Fix | Delete
}
[232] Fix | Delete
}
[233] Fix | Delete
[234] Fix | Delete
return $this->wrapper;
[235] Fix | Delete
}
[236] Fix | Delete
[237] Fix | Delete
/**
[238] Fix | Delete
* Retrieves the separator.
[239] Fix | Delete
*
[240] Fix | Delete
* @return string The separator.
[241] Fix | Delete
*/
[242] Fix | Delete
protected function get_separator() {
[243] Fix | Delete
if ( ! $this->separator ) {
[244] Fix | Delete
$this->separator = \apply_filters( 'wpseo_breadcrumb_separator', $this->helpers->options->get( 'breadcrumbs-sep' ) );
[245] Fix | Delete
$this->separator = ' ' . $this->separator . ' ';
[246] Fix | Delete
}
[247] Fix | Delete
[248] Fix | Delete
return $this->separator;
[249] Fix | Delete
}
[250] Fix | Delete
[251] Fix | Delete
/**
[252] Fix | Delete
* Retrieves the crumb element name.
[253] Fix | Delete
*
[254] Fix | Delete
* @return string The element to use.
[255] Fix | Delete
*/
[256] Fix | Delete
protected function get_element() {
[257] Fix | Delete
if ( ! $this->element ) {
[258] Fix | Delete
$this->element = \esc_attr( \apply_filters( 'wpseo_breadcrumb_single_link_wrapper', 'span' ) );
[259] Fix | Delete
}
[260] Fix | Delete
[261] Fix | Delete
return $this->element;
[262] Fix | Delete
}
[263] Fix | Delete
}
[264] Fix | Delete
[265] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function