HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/ijzerenman.komma.pro/app/Custom/Pages/MetaDataService.php
<?php


namespace Komma\Pages;


class MetaDataService
{
    /**
     * Get title
     *
     * @param $entity
     * @param array $parents
     * @return string
     */
    public function title($entity, $parents = [])
    {
        // If user entered a meta title, use that one
        if( $entity->meta_title != '') return $entity->meta_title;

        // Else: Get title from parents
        return $this->titleFromParents($parents);
    }


    /**
     * Generate title from parents
     *
     * @param array $parents
     * @return string
     */
    private function titleFromParents($parents)
    {
        $title = '';

        // Reverse parents
        $parents = array_reverse($parents);

        // Add Parents
        $i = 0;
        foreach($parents as $parent)
        {
            if($parent->codeName == 'home') continue;

            // Add to string
            if($i != 0) $title .= ' | ';
            $title .= $parent->name;
            $i++;
        }

        // Add global name
        $title .= ' | IJzeren Man Vught';

        return $title;
    }

    /**
     * See if there is a description on the page
     *
     * @param $entity
     * @return bool|string
     */
    public function description($entity)
    {
        // If user entered a meta description, use that one
        if( $entity->meta_description != '' ) return $entity->meta_description;

        // Get dynamic content
        $dynamic = json_decode($entity->description);

        // I need description
        if( empty($dynamic) || ! isset($dynamic[key($dynamic)]->description)) return false;

        // Return description
        return strip_tags($dynamic[key($dynamic)]->description);
    }
}