container = $container; $this->context = $context; $this->helpers = $this->container->get( Helpers_Surface::class ); $this->replace_vars = $this->container->get( WPSEO_Replace_Vars::class ); $this->front_end = $this->container->get( Front_End_Integration::class ); } /** * Returns the output as would be presented in the head. * * @return string The HTML output of the head. */ public function get_head() { $presenters = $this->front_end->get_presenters( $this->context->page_type ); if ( $this->context->page_type === 'Date_Archive' ) { $callback = static function ( $presenter ) { return ! \is_a( $presenter, Rel_Next_Presenter::class ) && ! \is_a( $presenter, Rel_Prev_Presenter::class ); }; $presenters = \array_filter( $presenters, $callback ); } $output = ''; /** This filter is documented in src/integrations/front-end-integration.php */ $presentation = \apply_filters( 'wpseo_frontend_presentation', $this->context->presentation, $this->context ); foreach ( $presenters as $presenter ) { $presenter->presentation = $presentation; $presenter->helpers = $this->helpers; $presenter->replace_vars = $this->replace_vars; $presenter_output = $presenter->present(); if ( ! empty( $presenter_output ) ) { $output .= $presenter_output . \PHP_EOL; } } return \trim( $output ); } /** * Magic getter for presenting values through the appropriate presenter, if it exists. * * @param string $name The property to get. * * @return mixed The value, as presented by teh appropriate presenter. * * @throws Exception If an invalid property is accessed. */ public function __get( $name ) { /** This filter is documented in src/integrations/front-end-integration.php */ $presentation = \apply_filters( 'wpseo_frontend_presentation', $this->context->presentation, $this->context ); if ( ! isset( $presentation->{$name} ) ) { if ( isset( $this->context->{$name} ) ) { $this->{$name} = $this->context->{$name}; return $this->{$name}; } return null; } $presenter_namespace = 'Yoast\WP\SEO\Presenters\\'; $parts = \explode( '_', $name ); if ( $parts[0] === 'twitter' ) { $presenter_namespace .= 'Twitter\\'; $parts = \array_slice( $parts, 1 ); } elseif ( $parts[0] === 'open' && $parts[1] === 'graph' ) { $presenter_namespace .= 'Open_Graph\\'; $parts = \array_slice( $parts, 2 ); } $presenter_class = $presenter_namespace . \implode( '_', \array_map( 'ucfirst', $parts ) ) . '_Presenter'; if ( \class_exists( $presenter_class ) ) { /** * The indexable presenter. * * @var Abstract_Indexable_Presenter */ $presenter = new $presenter_class(); $presenter->presentation = $presentation; $presenter->helpers = $this->helpers; $presenter->replace_vars = $this->replace_vars; $value = $presenter->get(); } else { $value = $presentation->{$name}; } $this->{$name} = $value; return $this->{$name}; } /** * Magic isset for ensuring properties on the presentation are recognised. * * @param string $name The property to get. * * @return bool Whether or not the requested property exists. */ public function __isset( $name ) { return isset( $this->context->presentation->{$name} ); } /** * Strips all nested dependencies from the debug info. * * @return array */ public function __debugInfo() { return [ 'context' => $this->context ]; } }