<commit_before><?php

namespace Innoweb\SocialMeta\Extensions;

use BetterBrief\GoogleMapField;
use BurnBright\ExternalURLField\ExternalURLField;
use Innoweb\SocialMeta\Model\BusinessLocation;
use Innoweb\SocialMeta\Model\OpeningHours;
use Sheadawson\DependentDropdown\Forms\DependentDropdownField;
use SilverStripe\AssetAdmin\Forms\UploadField;
use SilverStripe\Assets\Image;
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
use SilverStripe\Core\Config\Config;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\CheckboxSetField;
use SilverStripe\Forms\DatetimeField;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\EmailField;
use SilverStripe\Forms\FieldGroup;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\HeaderField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\TextareaField;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use SilverStripe\ORM\DataExtension;
use Symbiote\MultiValueField\Fields\MultiValueTextField;
use UncleCheese\DisplayLogic\Forms\Wrapper;

class ConfigExtension extends DataExtension
{
    private static $socialmeta_images_folder;
    private static $socialmeta_root_tab_name = 'Root.Metadata';

    private static $db = [
        'SocialMetaSiteName'            =>  'Varchar(255)',
        'SocialMetaSiteDescription'     =>  'Text',

        'SocialMetaFacebookPage'        =>  'ExternalURL',
        'SocialMetaFacebookAppID'       =>  'Varchar(20)',
        'SocialMetaFacebookAdminIDs'    =>  'MultiValueField',
        'SocialMetaTwitterAccount'      =>  'Varchar(20)',

        'MicroDataType'                 =>  'Varchar(255)',
        'MicroDataTypeSpecific'         =>  'Varchar(255)',

        'MicroDataStreetAddress'        =>  'Varchar(255)',
        'MicroDataPOBoxNumber'          =>  'Varchar(255)',
        'MicroDataCity'                 =>  'Varchar(255)',
        'MicroDataPostCode'             =>  'Varchar(255)',
        'MicroDataRegion'               =>  'Varchar(255)',
        'MicroDataCountry'              =>  'Varchar(255)',
        'MicroDataPhone'                =>  'Varchar(255)',
        'MicroDataFax'                  =>  'Varchar(255)',
        'MicroDataEmail'                =>  'Varchar(255)',

        'MicroDataPaymentAccepted'      =>  'Varchar(255)',

        'IsMicroDataCoordinatesEnabled' =>  'Boolean',
        'MicroDataGoogleMapsAPIKey'     =>  'Varchar(255)',
        'MicroDataLocationLongitude'    =>  'Varchar',
        'MicroDataLocationLatitude'     =>  'Varchar',

        'HasMicroDataAdditionalLocations'                   =>  'Boolean',
        'IsMicroDataAdditionalLocationsSeparateEntities'    =>  'Boolean',

        'MicroDataEventLocationName'    =>  'Varchar(255)',
        'MicroDataEventLocationWebsite' =>  'ExternalURL',
        'MicroDataEventStart'           =>  'Datetime',
        'MicroDataEventEnd'             =>  'Datetime',

        'SocialMetaSameAsLinks'         =>  'MultiValueField',
    ];

    private static $has_one = [
        'MicroDataSiteLogo'             =>  Image::class,
        'SocialMetaSiteImage'           =>  Image::class
    ];

    private static $has_many = [
        'MicroDataAdditionalLocations'  =>  BusinessLocation::class . '.SocialMetaConfigOf',
        'MicroDataOpeningHours'         =>  OpeningHours::class . '.SocialMetaConfigOf'
    ];

    private static $owns = [
        'MicroDataSiteLogo',
        'SocialMetaSiteImage',
        'MicroDataAdditionalLocations',
        'MicroDataOpeningHours'
    ];

    private static $cascade_deletes = [
        'MicroDataAdditionalLocations',
        'MicroDataOpeningHours'
    ];

    public function getMicroDataSchemaData()
    {
        $currentPage = Director::get_current_page();

        $data = [
            '@context'  =>  'http://schema.org',
            '@type'     =>  $this->owner->getMicroDataSchemaType(),
            '@id'       =>  $this->owner->getSocialMetaValue('SchemaSiteID'),
        ];

        if ($this->owner->getSocialMetaValue('SiteName')) {
            $data['name'] = $this->owner->getSocialMetaValue('SiteName');
        }

        if ($this->owner->getSocialMetaValue('SiteDescription')) {
            $data['description'] = $this->owner->getSocialMetaValue('SiteDescription');
        }

        $logo = $this->owner->getSocialMetaValue('SiteLogo');
        if ($logo && $logo->exists()) {
            $data['logo'] = [
                '@type'     =>  'ImageObject',
                'url'       =>  $logo->getAbsoluteURL(),
                'width'     =>  $logo->getWidth() . 'px',
                'height'    =>  $logo->getHeight() . 'px'
            ];<commit_msg>add mainEntityOfPage to site ld+json data using SiteURL<commit_after><?php

namespace Innoweb\SocialMeta\Extensions;

use BetterBrief\GoogleMapField;
use BurnBright\ExternalURLField\ExternalURLField;
use Innoweb\SocialMeta\Model\BusinessLocation;
use Innoweb\SocialMeta\Model\OpeningHours;
use Sheadawson\DependentDropdown\Forms\DependentDropdownField;
use SilverStripe\AssetAdmin\Forms\UploadField;
use SilverStripe\Assets\Image;
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
use SilverStripe\Core\Config\Config;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\CheckboxSetField;
use SilverStripe\Forms\DatetimeField;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\EmailField;
use SilverStripe\Forms\FieldGroup;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\HeaderField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\TextareaField;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use SilverStripe\ORM\DataExtension;
use Symbiote\MultiValueField\Fields\MultiValueTextField;
use UncleCheese\DisplayLogic\Forms\Wrapper;

class ConfigExtension extends DataExtension
{
    private static $socialmeta_images_folder;
    private static $socialmeta_root_tab_name = 'Root.Metadata';

    private static $db = [
        'SocialMetaSiteName'            =>  'Varchar(255)',
        'SocialMetaSiteDescription'     =>  'Text',

        'SocialMetaFacebookPage'        =>  'ExternalURL',
        'SocialMetaFacebookAppID'       =>  'Varchar(20)',
        'SocialMetaFacebookAdminIDs'    =>  'MultiValueField',
        'SocialMetaTwitterAccount'      =>  'Varchar(20)',

        'MicroDataType'                 =>  'Varchar(255)',
        'MicroDataTypeSpecific'         =>  'Varchar(255)',

        'MicroDataStreetAddress'        =>  'Varchar(255)',
        'MicroDataPOBoxNumber'          =>  'Varchar(255)',
        'MicroDataCity'                 =>  'Varchar(255)',
        'MicroDataPostCode'             =>  'Varchar(255)',
        'MicroDataRegion'               =>  'Varchar(255)',
        'MicroDataCountry'              =>  'Varchar(255)',
        'MicroDataPhone'                =>  'Varchar(255)',
        'MicroDataFax'                  =>  'Varchar(255)',
        'MicroDataEmail'                =>  'Varchar(255)',

        'MicroDataPaymentAccepted'      =>  'Varchar(255)',

        'IsMicroDataCoordinatesEnabled' =>  'Boolean',
        'MicroDataGoogleMapsAPIKey'     =>  'Varchar(255)',
        'MicroDataLocationLongitude'    =>  'Varchar',
        'MicroDataLocationLatitude'     =>  'Varchar',

        'HasMicroDataAdditionalLocations'                   =>  'Boolean',
        'IsMicroDataAdditionalLocationsSeparateEntities'    =>  'Boolean',

        'MicroDataEventLocationName'    =>  'Varchar(255)',
        'MicroDataEventLocationWebsite' =>  'ExternalURL',
        'MicroDataEventStart'           =>  'Datetime',
        'MicroDataEventEnd'             =>  'Datetime',

        'SocialMetaSameAsLinks'         =>  'MultiValueField',
    ];

    private static $has_one = [
        'MicroDataSiteLogo'             =>  Image::class,
        'SocialMetaSiteImage'           =>  Image::class
    ];

    private static $has_many = [
        'MicroDataAdditionalLocations'  =>  BusinessLocation::class . '.SocialMetaConfigOf',
        'MicroDataOpeningHours'         =>  OpeningHours::class . '.SocialMetaConfigOf'
    ];

    private static $owns = [
        'MicroDataSiteLogo',
        'SocialMetaSiteImage',
        'MicroDataAdditionalLocations',
        'MicroDataOpeningHours'
    ];

    private static $cascade_deletes = [
        'MicroDataAdditionalLocations',
        'MicroDataOpeningHours'
    ];

    public function getMicroDataSchemaData()
    {
        $currentPage = Director::get_current_page();

        $data = [
            '@context'          =>  'http://schema.org',
            '@type'             =>  $this->owner->getMicroDataSchemaType(),
            '@id'               =>  $this->owner->getSocialMetaValue('SchemaSiteID'),
            'mainEntityOfPage'  =>  $this->owner->getSocialMetaValue('SiteURL'),
        ];

        if ($this->owner->getSocialMetaValue('SiteName')) {
            $data['name'] = $this->owner->getSocialMetaValue('SiteName');
        }

        if ($this->owner->getSocialMetaValue('SiteDescription')) {
            $data['description'] = $this->owner->getSocialMetaValue('SiteDescription');
        }

        $logo = $this->owner->getSocialMetaValue('SiteLogo');
        if ($logo && $logo->exists()) {
            $data['logo'] = [
                '@type'     =>  'ImageObject',
                'url'       =>  $logo->getAbsoluteURL(),
                'width'     =>  $logo->getWidth() . 'px',
                'height'    =>  $logo->getHeight() . 'px'
            ];
{'fraction_non_alphanumeric': 0.12627986348122866, 'fraction_numerical': 0.010135484538214914, 'mean_word_length': 2.6095558044046285, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 122, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4720036', 'n_tokens_mistral': 3068, 'n_tokens_neox': 2829, 'n_words': 391}