<?php
/**
 * AuroraCMS - Copyright (C) Diemen Design 2019
 *
 * @category   Administration - View - Include Breadcrumbs
 * @package    core/view/inc-breadcrumbs.php
 * @author     Dennis Suitters <dennis@diemen.design>
 * @copyright  2014-2019 Diemen Design
 * @license    http://opensource.org/licenses/MIT  MIT License
 * @version    0.2.3
 * @link       https://github.com/DiemenDesign/AuroraCMS
 * @notes      This PHP Script is designed to be executed using PHP 7+
 */
if(stristr($html,'<breadcrumb>')){
  preg_match('/<breaditems>([\w\W]*?)<\/breaditems>/',$html,$matches);
  $breaditem=$matches[1];
  preg_match('/<breadcurrent>([\w\W]*?)<\/breadcurrent>/',$html,$matches);
  $breadcurrent=$matches[1];
  $jsonld='<script type="application/ld+json">{'.
		'"@context":"http://schema.org",'.
		'"@type":"BreadcrumbList",'.
		'"itemListElement":[{'.
			'"@type":"ListItem",'.
			'"position":1,'.
			'"item":{'.
				'"@id":"'.URL.'",'.
				'"name":"Home"'.
			'}'.
		'},';
  $breadit=preg_replace([
    '/<print breadcrumb=[\"\']?url[\"\']?>/',
    '/<print breadcrumb=[\"\']?title[\"\']?>/'
  ],[
    URL,
    'Home'
  ],$breaditem);
  $breaditems=$breadit;
  $breadit=preg_replace('/<print breadcrumb=[\"\']?title[\"\']?>/',htmlspecialchars(ucwords($page['title']),ENT_QUOTES,'UTF-8'),$breadcurrent);
  $jsonld.=
	'{'.
		'"@type":"ListItem",'.
		'"position":2,'.
		'"item":{'.
			'"@id":"'.URL.urlencode($page['contentType']).'",'.
			'"name":"'.htmlspecialchars(ucwords($page['title']),ENT_QUOTES,'UTF-8').'"'.
		'}'.
	'}]}</script>';
  $breaditems.=$breadit;
  $html=preg_replace([
    '/<[\/]?breadcrumb>/',
    '/<json-ld-breadcrumb>/',
    '~<breaditems>.*?<\/breaditems>~is',
    '~<breadcurrent>.*?<\/breadcurrent>~is'
  ],[
    '',
    $jsonld,
    $breaditems,
    ''
  ],$html);
}
