Created
June 6, 2025 14:54
-
-
Save EscApp2/e609ac2e52831ad4d846d0a2cd97042a to your computer and use it in GitHub Desktop.
breadcrumbs schema.org
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <? | |
| AddEventHandler("main", "OnEndBufferContent", "AddMicrodataBreadCrumbs",99999); | |
| function AddMicrodataBreadCrumbs(&$content){ | |
| global $APPLICATION; | |
| if(defined('ADMIN_SECTION')){ | |
| return true; | |
| } | |
| $dir = $APPLICATION->GetCurDir(false); | |
| if(strpos($dir, '/bitrix/admin/') !== false){ | |
| return true; | |
| } | |
| if(strpos($dir, '/bitrix/gadgets/') !== false){ | |
| return true; | |
| } | |
| if(strpos($dir, '/bitrix/tools/') !== false){ | |
| return true; | |
| } | |
| if(strpos($dir, '/upload/') !== false){ | |
| return true; | |
| } | |
| if( | |
| !empty($_SERVER['HTTP_X_REQUESTED_WITH']) | |
| && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' | |
| ){ | |
| return true; | |
| } | |
| if($_SERVER['REQUEST_METHOD'] != "GET"){ | |
| return true; | |
| } | |
| $path = $APPLICATION->GetCurPage(); | |
| $template = SITE_TEMPLATE_PATH."/schema_breadcrumbs.php"; | |
| $schema = $APPLICATION->GetNavChain($path , 0 , $template, true, false); | |
| $content = AddScriptCustom::addHeadScript($schema, $content); | |
| } | |
| class AddScriptCustom | |
| { | |
| //from arturgolubev.abandoned unitools class | |
| static function addHeadScript($script, $oldBuffer) | |
| { | |
| $search = '</head>'; | |
| $replace = $script . PHP_EOL . $search; | |
| $bufferContent = $oldBuffer; | |
| if (substr_count($oldBuffer, $search) == 1) { | |
| $bufferContent = str_replace($search, $replace, $oldBuffer); | |
| } else { | |
| $bodyEnd = self::getLastPositionIgnoreCase($oldBuffer, $search); | |
| if ($bodyEnd !== false) { | |
| $bufferContent = substr_replace($oldBuffer, $replace, $bodyEnd, strlen($search)); | |
| } | |
| } | |
| return $bufferContent; | |
| } | |
| static function addBodyScript($script, $oldBuffer) | |
| { | |
| $search = '</body>'; | |
| $replace = $script . PHP_EOL . $search; | |
| $bufferContent = $oldBuffer; | |
| if (substr_count($oldBuffer, $search) == 1) { | |
| $bufferContent = str_replace($search, $replace, $oldBuffer); | |
| } else { | |
| $bodyEnd = self::getLastPositionIgnoreCase($oldBuffer, $search); | |
| if ($bodyEnd !== false) { | |
| $bufferContent = substr_replace($oldBuffer, $replace, $bodyEnd, strlen($search)); | |
| } | |
| } | |
| return $bufferContent; | |
| } | |
| static function getLastPositionIgnoreCase($haystack, $needle, $offset = 0) | |
| { | |
| if (defined("BX_UTF")) { | |
| if (function_exists("mb_orig_strripos")) { | |
| return mb_orig_strripos($haystack, $needle, $offset); | |
| } | |
| return mb_strripos($haystack, $needle, $offset, "latin1"); | |
| } | |
| return strripos($haystack, $needle, $offset); | |
| } | |
| static function getFirstPositionIgnoreCase($haystack, $needle, $offset = 0) | |
| { | |
| if (defined("BX_UTF")) { | |
| if (function_exists("mb_orig_stripos")) { | |
| return mb_orig_stripos($haystack, $needle, $offset); | |
| } | |
| return mb_stripos($haystack, $needle, $offset, "latin1"); | |
| } | |
| return stripos($haystack, $needle, $offset); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment