Sindbad~EG File Manager

Current Path : /home/xiedrke/entrepot/wp-content/plugins/realpress/app/Controllers/
Upload File :
Current File : /home/xiedrke/entrepot/wp-content/plugins/realpress/app/Controllers/SchemaController.php

<?php

namespace RealPress\Controllers;

class SchemaController {

	public $breadcrumb_data = array();

	public function __construct() {
		add_action( 'realpress/layout/breadcrumb/container/before', array( $this, 'breadcrumb_markup' ) );
		add_action( 'wp_footer', array( $this, 'add_breadcrumb_markup' ), 10 );
	}

	/**
	 * @param $breadcrumbs
	 *
	 * @return void
	 */
	public function breadcrumb_markup( $breadcrumbs ) {
		if ( empty( $breadcrumbs ) ) {
			return;
		}

		$markup                    = array();
		$markup['@type']           = 'BreadcrumbList';
		$markup['itemListElement'] = array();

		foreach ( $breadcrumbs as $key => $breadcrumb ) {
			$markup['itemListElement'][ $key ] = array(
				'@type'    => 'ListItem',
				'position' => $key + 1,
				'item'     => array(
					'name' => $breadcrumb['title'],
				),
			);

			if ( ! empty( $breadcrumb['link'] ) ) {
				$markup['itemListElement'][ $key ]['item']['@id'] = $breadcrumb['link'];
			}
		}

		$this->breadcrumb_data[] =
			apply_filters(
				'realpress/filter/structured_data/breadcrumblist',
				$markup,
				$breadcrumbs
			);
	}

	/**
	 * @return void
	 */
	public function add_breadcrumb_markup() {
		$data = $this->get_structured_data();

		if ( ! empty( $data ) ) {
			echo '<script type="application/ld+json">' . wp_json_encode( $data ) . '</script>';
		}
	}

	/**
	 * @return array|mixed|string[]
	 */
	public function get_structured_data() {
		$data = array();

		foreach ( $this->breadcrumb_data as $value ) {
			$data[ strtolower( $value['@type'] ) ][] = $value;
		}

		foreach ( $data as $type => $value ) {
			$data[ $type ] = count( $value ) > 1 ? array( '@graph' => $value ) : $value[0];
			$data[ $type ] = array( '@context' => 'https://schema.org/' ) + $data[ $type ];
		}

		$types = apply_filters( 'realpress/filter/structured_data/types', array( 'breadcrumblist' ) );

		$data = $types ? array_values( array_intersect_key( $data, array_flip( $types ) ) ) : array_values( $data );
		if ( ! empty( $data ) ) {
			if ( 1 < count( $data ) ) {
				$data = array( '@context' => 'https://schema.org/' ) + array( '@graph' => $data );
			} else {
				$data = $data[0];
			}
		}

		return $data;
	}
}

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists