Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/wordpres.../src/generato.../schema
File: howto.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Generators\Schema;
[2] Fix | Delete
[3] Fix | Delete
use Yoast\WP\SEO\Config\Schema_IDs;
[4] Fix | Delete
[5] Fix | Delete
/**
[6] Fix | Delete
* Returns schema HowTo data.
[7] Fix | Delete
*/
[8] Fix | Delete
class HowTo extends Abstract_Schema_Piece {
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* Determines whether or not a piece should be added to the graph.
[12] Fix | Delete
*
[13] Fix | Delete
* @return bool
[14] Fix | Delete
*/
[15] Fix | Delete
public function is_needed() {
[16] Fix | Delete
return ! empty( $this->context->blocks['yoast/how-to-block'] );
[17] Fix | Delete
}
[18] Fix | Delete
[19] Fix | Delete
/**
[20] Fix | Delete
* Renders a list of questions, referencing them by ID.
[21] Fix | Delete
*
[22] Fix | Delete
* @return array Our Schema graph.
[23] Fix | Delete
*/
[24] Fix | Delete
public function generate() {
[25] Fix | Delete
$graph = [];
[26] Fix | Delete
[27] Fix | Delete
foreach ( $this->context->blocks['yoast/how-to-block'] as $index => $block ) {
[28] Fix | Delete
$this->add_how_to( $graph, $block, $index );
[29] Fix | Delete
}
[30] Fix | Delete
[31] Fix | Delete
return $graph;
[32] Fix | Delete
}
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* Adds the duration of the task to the Schema.
[36] Fix | Delete
*
[37] Fix | Delete
* @param array $data Our How-To schema data.
[38] Fix | Delete
* @param array $attributes The block data attributes.
[39] Fix | Delete
*
[40] Fix | Delete
* @return void
[41] Fix | Delete
*/
[42] Fix | Delete
private function add_duration( &$data, $attributes ) {
[43] Fix | Delete
if ( empty( $attributes['hasDuration'] ) ) {
[44] Fix | Delete
return;
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
$days = empty( $attributes['days'] ) ? 0 : $attributes['days'];
[48] Fix | Delete
$hours = empty( $attributes['hours'] ) ? 0 : $attributes['hours'];
[49] Fix | Delete
$minutes = empty( $attributes['minutes'] ) ? 0 : $attributes['minutes'];
[50] Fix | Delete
[51] Fix | Delete
if ( ( $days + $hours + $minutes ) > 0 ) {
[52] Fix | Delete
$data['totalTime'] = \esc_attr( 'P' . $days . 'DT' . $hours . 'H' . $minutes . 'M' );
[53] Fix | Delete
}
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
/**
[57] Fix | Delete
* Adds the steps to our How-To output.
[58] Fix | Delete
*
[59] Fix | Delete
* @param array $data Our How-To schema data.
[60] Fix | Delete
* @param array $steps Our How-To block's steps.
[61] Fix | Delete
*
[62] Fix | Delete
* @return void
[63] Fix | Delete
*/
[64] Fix | Delete
private function add_steps( &$data, $steps ) {
[65] Fix | Delete
foreach ( $steps as $step ) {
[66] Fix | Delete
$schema_id = $this->context->canonical . '#' . \esc_attr( $step['id'] );
[67] Fix | Delete
$schema_step = [
[68] Fix | Delete
'@type' => 'HowToStep',
[69] Fix | Delete
'url' => $schema_id,
[70] Fix | Delete
];
[71] Fix | Delete
[72] Fix | Delete
if ( isset( $step['jsonText'] ) ) {
[73] Fix | Delete
$json_text = $this->helpers->schema->html->sanitize( $step['jsonText'] );
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
if ( isset( $step['jsonName'] ) ) {
[77] Fix | Delete
$json_name = $this->helpers->schema->html->smart_strip_tags( $step['jsonName'] );
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
if ( empty( $json_name ) ) {
[81] Fix | Delete
if ( empty( $step['text'] ) ) {
[82] Fix | Delete
continue;
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
$schema_step['text'] = '';
[86] Fix | Delete
[87] Fix | Delete
$this->add_step_image( $schema_step, $step );
[88] Fix | Delete
[89] Fix | Delete
// If there is no text and no image, don't output the step.
[90] Fix | Delete
if ( empty( $json_text ) && empty( $schema_step['image'] ) ) {
[91] Fix | Delete
continue;
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
if ( ! empty( $json_text ) ) {
[95] Fix | Delete
$schema_step['text'] = $json_text;
[96] Fix | Delete
}
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
elseif ( empty( $json_text ) ) {
[100] Fix | Delete
$schema_step['text'] = $json_name;
[101] Fix | Delete
}
[102] Fix | Delete
else {
[103] Fix | Delete
$schema_step['name'] = $json_name;
[104] Fix | Delete
[105] Fix | Delete
$this->add_step_description( $schema_step, $json_text );
[106] Fix | Delete
$this->add_step_image( $schema_step, $step );
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
$data['step'][] = $schema_step;
[110] Fix | Delete
}
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
/**
[114] Fix | Delete
* Checks if we have a step description, if we do, add it.
[115] Fix | Delete
*
[116] Fix | Delete
* @param array $schema_step Our Schema output for the Step.
[117] Fix | Delete
* @param string $json_text The step text.
[118] Fix | Delete
*
[119] Fix | Delete
* @return void
[120] Fix | Delete
*/
[121] Fix | Delete
private function add_step_description( &$schema_step, $json_text ) {
[122] Fix | Delete
$schema_step['itemListElement'] = [
[123] Fix | Delete
[
[124] Fix | Delete
'@type' => 'HowToDirection',
[125] Fix | Delete
'text' => $json_text,
[126] Fix | Delete
],
[127] Fix | Delete
];
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
/**
[131] Fix | Delete
* Checks if we have a step image, if we do, add it.
[132] Fix | Delete
*
[133] Fix | Delete
* @param array $schema_step Our Schema output for the Step.
[134] Fix | Delete
* @param array $step The step block data.
[135] Fix | Delete
*
[136] Fix | Delete
* @return void
[137] Fix | Delete
*/
[138] Fix | Delete
private function add_step_image( &$schema_step, $step ) {
[139] Fix | Delete
if ( isset( $step['text'] ) && \is_array( $step['text'] ) ) {
[140] Fix | Delete
foreach ( $step['text'] as $line ) {
[141] Fix | Delete
if ( \is_array( $line ) && isset( $line['type'] ) && $line['type'] === 'img' ) {
[142] Fix | Delete
$schema_step['image'] = $this->get_image_schema( \esc_url( $line['props']['src'] ) );
[143] Fix | Delete
}
[144] Fix | Delete
}
[145] Fix | Delete
}
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
/**
[149] Fix | Delete
* Generates the HowTo schema for a block.
[150] Fix | Delete
*
[151] Fix | Delete
* @param array $graph Our Schema data.
[152] Fix | Delete
* @param array $block The How-To block content.
[153] Fix | Delete
* @param int $index The index of the current block.
[154] Fix | Delete
*
[155] Fix | Delete
* @return void
[156] Fix | Delete
*/
[157] Fix | Delete
protected function add_how_to( &$graph, $block, $index ) {
[158] Fix | Delete
$data = [
[159] Fix | Delete
'@type' => 'HowTo',
[160] Fix | Delete
'@id' => $this->context->canonical . '#howto-' . ( $index + 1 ),
[161] Fix | Delete
'name' => $this->helpers->schema->html->smart_strip_tags( $this->helpers->post->get_post_title_with_fallback( $this->context->id ) ),
[162] Fix | Delete
'mainEntityOfPage' => [ '@id' => $this->context->main_schema_id ],
[163] Fix | Delete
'description' => '',
[164] Fix | Delete
];
[165] Fix | Delete
[166] Fix | Delete
if ( $this->context->has_article ) {
[167] Fix | Delete
$data['mainEntityOfPage'] = [ '@id' => $this->context->main_schema_id . Schema_IDs::ARTICLE_HASH ];
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
if ( isset( $block['attrs']['jsonDescription'] ) ) {
[171] Fix | Delete
$data['description'] = $this->helpers->schema->html->sanitize( $block['attrs']['jsonDescription'] );
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
$this->add_duration( $data, $block['attrs'] );
[175] Fix | Delete
[176] Fix | Delete
if ( isset( $block['attrs']['steps'] ) ) {
[177] Fix | Delete
$this->add_steps( $data, $block['attrs']['steps'] );
[178] Fix | Delete
}
[179] Fix | Delete
[180] Fix | Delete
$data = $this->helpers->schema->language->add_piece_language( $data );
[181] Fix | Delete
[182] Fix | Delete
$graph[] = $data;
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
/**
[186] Fix | Delete
* Generates the image schema from the attachment $url.
[187] Fix | Delete
*
[188] Fix | Delete
* @param string $url Attachment url.
[189] Fix | Delete
*
[190] Fix | Delete
* @return array Image schema.
[191] Fix | Delete
*/
[192] Fix | Delete
protected function get_image_schema( $url ) {
[193] Fix | Delete
$schema_id = $this->context->canonical . '#schema-image-' . \md5( $url );
[194] Fix | Delete
[195] Fix | Delete
return $this->helpers->schema->image->generate_from_url( $schema_id, $url );
[196] Fix | Delete
}
[197] Fix | Delete
}
[198] Fix | Delete
[199] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function