Find the location on design bases on the disk

@param $ini an eZINI object
@param $siteAccess Wether to use siteaccesses or not
@return array The list of design bases
511991
private static function findDesignBase( eZINI $ini, $siteAccess = false )
    {
        if( $siteAccess )
        {
            $ini = eZSiteAccess::getIni( $siteAccess, 'site.ini' );

            $standardDesign = $ini->variable( 'DesignSettings', 'StandardDesign' );
            $siteDesign     = $ini->variable( 'DesignSettings', 'SiteDesign' );

        }
        else
        {
            $ini = eZINI::instance();
            $standardDesign = eZTemplateDesignResource::designSetting( 'standard' );
            $siteDesign     = eZTemplateDesignResource::designSetting( 'site' );
        }

        $siteDesignList = $ini->variable( 'DesignSettings', 'AdditionalSiteDesignList' );

        array_unshift( $siteDesignList, $siteDesign );
        $siteDesignList[] = $standardDesign;
        $siteDesignList   = array_unique( $siteDesignList );

        $designBaseList     = array();
        $extensionDirectory = eZExtension::baseDirectory();
        $designStartPath    = eZTemplateDesignResource::designStartPath();
        $extensions         = eZTemplateDesignResource::designExtensions();

        foreach ( $siteDesignList as $design )
        {
            foreach ( $extensions as $extension )
            {
                $path = "$extensionDirectory/$extension/$designStartPath/$design";
                if ( file_exists( $path ) )
                {
                    $designBaseList[] = $path;
                }
            }

            $path = "$designStartPath/$design";
            if ( file_exists( $path ) )
            {
                $designBaseList[] = $path;
            }
        }

        return $designBaseList;
    }
1373695
public function setSiteAccess(SiteAccess $siteAccess = null)
    {
        if ($this->logger) {
            $this->logger->debug('Changing SiteAccess in view providers');
        }

        $providers = array_merge(
            $this->getAllLocationViewProviders(),
            $this->getAllContentViewProviders(),
            $this->getAllBlockViewProviders()
        );
        foreach ($providers as $provider) {
            if ($provider instanceof SiteAccessAware) {
                $provider->setSiteAccess($siteAccess);
            }
        }
    }
611531
public function getSettingList(Site $site)
    {
        $settingList = [];
        $items       = $this->getSettingBySiteId($site->getId());
        /** @var $setting \PageBuilder\Entity\Setting */
        foreach ($items as $setting) {
            $code               = $setting->getSettingKey()->getCode();
            $value              = $setting->getSettingValue() ?: $setting->getSettingKey()->getDefaultValue();
            $settingList[$code] = $value;
        }

        $locale                = $site->getLocale() ?: 'en_GB';
        $settingList           = array_merge($settingList, \Locale::parseLocale($locale));
        $settingList['locale'] = $locale;

        return $settingList;
    }
786615
static function showInvisibleNodes()
    {
        static $cachedResult;

        if ( !isset( $cachedResult ) )
        {
            $ini = eZINI::instance( 'site.ini' );
            $cachedResult = $ini->hasVariable( 'SiteAccessSettings', 'ShowHiddenNodes' ) ?
                            $ini->variable( 'SiteAccessSettings', 'ShowHiddenNodes' ) == 'true' :
                            true;
        }

        return $cachedResult;
    }
690845
public function getLanguages($mandatorId = null, $siteAccess = null)
    {
        if ($mandatorId) {
            $languages = $this->getMainLanguagesBySiteAccesses(
                $this->getSiteAccessesByMandatorId($mandatorId)
            );
        } elseif ($siteAccess) {
            $languages = $this->configResolver->getParameter('languages', '', $siteAccess);
        } else {
            $languages = $this->configResolver->getParameter('languages');
        }

        if (empty($languages)) {
            throw new LogicException(sprintf('No languages found using SiteAccess or mandatorId'));
        }

        return $languages;
    }
774294
private function getCurrentSite(Site $site = null)
    {
        if (null !== $site) {
            return $site;
        }

        if (null !== $this->application) {
            return $this->application->getSite();
        }

        return null;
    }
832226
public static function validateSiteAccessName(string $siteaccess = null): string
    {
        // We allow empty siteaccess name in order to quit asking for more
        if (empty($siteaccess)) {
            return '';
        }

        if (!preg_match('/^[a-z][a-z0-9_]*$/', $siteaccess)) {
            throw new InvalidArgumentException('Siteaccess name is not valid.');
        }

        self::validateReservedKeywords($siteaccess);

        return $siteaccess;
    }
14792
public function setSiteAccess(SiteAccess $siteAccess = null)
    {
        if ($siteAccess === null) {
            return;
        }

        $this->matchConfig = $this->configResolver->getParameter('block_view', 'ezsettings', $siteAccess->name);
    }
670263
public function getAvailableSitesSelector(
        $selectorName,
        Site $selectedSite = null
    ) {
        $siteRepository = GeneralUtility::makeInstance(SiteRepository::class);

        $sites = $siteRepository->getAvailableSites();
        $selector = '<select name="' . htmlspecialchars($selectorName) . '" class="form-control">';

        foreach ($sites as $site) {
            $selectedAttribute = '';
            if ($selectedSite !== null && $site->getRootPageId() === $selectedSite->getRootPageId()) {
                $selectedAttribute = ' selected="selected"';
            }

            $selector .= '<option value="' . htmlspecialchars($site->getRootPageId()) . '"' . $selectedAttribute . '>'
                . htmlspecialchars($site->getLabel())
                . '</option>';
        }

        $selector .= '</select>';

        return $selector;
    }
127241
public function vote($siteAccess, array $routeConfig)
    {
        if (in_array($siteAccess, $routeConfig, true)) {
            return true;
        }

        return VoterInterface::ABSTAIN;
    }
970958
public static function getRootPageIdsFromSites(array $sites): array
    {
        $rootPageIds = [];
        foreach ($sites as $site) {
            $rootPageIds[] = (int)$site->getRootPageId();
        }

        return $rootPageIds;
    }
1211229
function overrideKeys( $siteAccess = false )
    {
//        print( "<br>" . xdebug_call_function() . "<br>" );
        $keys = array();
        $designStartPath = eZTemplateDesignResource::designStartPath();
        $keys[] = $designStartPath;

        // fetch the override array from a specific siteacces
        if ( $siteAccess )
        {
            // Get the design resources
            $ini = eZSiteAccess::getIni( $siteAccess, 'site.ini' );

            $overrideINI = eZINI::instance( 'override.ini', 'settings', null, null, true );

            // overwrite overrideDirs from siteIni instance
            $overrideINI->setOverrideDirs( $ini->overrideDirs( false ) );
            $overrideINI->load();

            $standardBase = $ini->variable( "DesignSettings", "StandardDesign" );
            $keys[] = "siteaccess/$siteAccess";
            $keys[] = $standardBase;
            $siteBase = $ini->variable( "DesignSettings", "SiteDesign" );
            $keys[] = $siteBase;
        }
        else
        {
            $ini = eZINI::instance();
            if ( $this->OverrideSiteAccess != false )
            {
                $overrideINI = eZSiteAccess::getIni( $siteAccess, 'override.ini' );
                $keys[] = "siteaccess/$this->OverrideSiteAccess";
            }
            else
            {
                $overrideINI = eZINI::instance( 'override.ini' );
                $siteAccess = $GLOBALS['eZCurrentAccess']['name'];
                $keys[] = "siteaccess/$siteAccess";
            }

            $standardBase = eZTemplateDesignResource::designSetting( 'standard' );
            $keys[] = $standardBase;
            $siteBase = eZTemplateDesignResource::designSetting( 'site' );
            $keys[] = $siteBase;
        }


        $additionalSiteDesignList = $ini->variable( "DesignSettings", "AdditionalSiteDesignList" );
        $keys = array_merge( $keys, $additionalSiteDesignList );

        // Add extension paths
        $extensionDirectory = eZExtension::baseDirectory();

        $designINI = eZINI::instance( 'design.ini' );
        $extensions = $designINI->variable( 'ExtensionSettings', 'DesignExtensions' );

        return  array_merge( $keys, $extensions );
    }
852691
public function getSiteAccesses($mandatorId = null, $siteAccess = null)
    {
        if ($mandatorId) {
            $siteAccesses = $this->getSiteaccessesByMandatorId($mandatorId);
        } elseif ($siteAccess) {
            $siteAccesses = array($siteAccess);
        } else {
            $siteAccesses = array($this->siteAccess->name);
        }

        return $siteAccesses;
    }
931960
public function canAccessMenuAdmin(AccountInterface $account, Site $site = null)
    {
        if ($account->hasPermission(self::PERM_MANAGE_ALL_MENU)) {
            return true;
        }

        $site = $this->ensureSiteContext($site);

        if ($site) {
            return $this->siteManager->getAccess()->userIsWebmaster($account, $site);
        } else {
            return $this->siteManager->getAccess()->userIsWebmaster($account);
        }

        return  false;
    }
745428
protected function getImageVariationsForSiteaccess($siteaccess)
    {
        $variations = [];
        $imageAliasesList = $this->getGroup('AliasSettings', 'image.ini', $siteaccess);
        foreach ($imageAliasesList['AliasList'] as $imageAliasIdentifier) {
            $variationSettings = ['reference' => null, 'filters' => []];
            $aliasSettings = $this->getGroup($imageAliasIdentifier, 'image.ini', $siteaccess);
            if (isset($aliasSettings['Reference']) && $aliasSettings['Reference'] != '') {
                $variationSettings['reference'] = $aliasSettings['Reference'];
            }
            if (isset($aliasSettings['Filters']) && \is_array($aliasSettings['Filters'])) {
                // parse filters. Format: filtername=param1;param2...paramN
                foreach ($aliasSettings['Filters'] as $filterString) {
                    $filteringSettings = [];

                    if (strstr($filterString, '=') !== false) {
                        list($filteringSettings['name'], $filterParams) = explode('=', $filterString);
                        $filterParams = explode(';', $filterParams);

                        // make sure integers are actually integers, not strings
                        array_walk(
                            $filterParams,
                            static function (&$value) {
                                if (preg_match('/^[0-9]+$/', $value)) {
                                    $value = (int)$value;
                                }
                            }
                        );

                        $filteringSettings['params'] = $filterParams;
                    } else {
                        $filteringSettings['name'] = $filterString;
                    }

                    $variationSettings['filters'][] = $filteringSettings;
                }
            }
            $variations[$imageAliasIdentifier] = $variationSettings;
        }

        return $variations;
    }
153158
protected function changeSiteAccessSetting( $siteaccess )
    {
        $cli = eZCLI::instance();
        if ( !in_array( $siteaccess, eZINI::instance()->variable( 'SiteAccessSettings', 'AvailableSiteAccessList' ) ) )
        {
            $cli->notice( "Siteaccess $siteaccess does not exist, using default siteaccess" );
        }
    }
713328
public function generate(InputInterface $input, OutputInterface $output): void
    {
        $settings = [];

        // List of siteaccesses and groups

        $siteAccessList = $input->getOption('site-access-list');
        $siteAccessNames = array_keys($siteAccessList);

        $adminSiteAccessNames = [
            self::NGADMINUI_SITEACCESS_NAME,
            self::EZPLATFORM_ADMIN_SITEACCESS_NAME,
            self::LEGACY_ADMIN_SITEACCESS_NAME,
        ];

        $adminSiteAccessLanguages = array_values(array_unique(array_merge(...array_values($siteAccessList))));

        $settings['ezpublish']['siteaccess']['default_siteaccess'] = $siteAccessNames[0];
        $settings['ezpublish']['siteaccess']['list'] = array_merge(
            $siteAccessNames,
            $adminSiteAccessNames
        );

        $settings['ezpublish']['siteaccess']['groups']['frontend_group'] = $siteAccessNames;
        $settings['ezpublish']['siteaccess']['groups']['ngadmin_group'] = [self::NGADMINUI_SITEACCESS_NAME, self::LEGACY_ADMIN_SITEACCESS_NAME];
        $settings['ezpublish']['siteaccess']['groups']['admin_group'] = [self::EZPLATFORM_ADMIN_SITEACCESS_NAME];

        // List of siteaccess languages

        $settings['ezpublish']['system'] = [];

        if (count($siteAccessNames) > 1) {
            $settings['ezpublish']['system']['frontend_group']['translation_siteaccesses'] = $siteAccessNames;
        }

        $settings['netgen_block_manager']['design_list']['app'] = ['app'];
        $settings['netgen_block_manager']['system']['frontend_group']['design'] = 'app';

        $settings['ezdesign']['design_list']['app'] = ['app', 'common'];
        $settings['ezdesign']['design_list'][self::NGADMINUI_SITEACCESS_NAME] = [
            self::NGADMINUI_SITEACCESS_NAME,
            'common',
        ];

        foreach ($siteAccessList as $siteAccessName => $siteAccessLanguages) {
            $settings['ezpublish']['system'][$siteAccessName]['design'] = 'app';
            $settings['ezpublish']['system'][$siteAccessName]['languages'] = $siteAccessLanguages;
            $settings['ezpublish']['system'][$siteAccessName]['session'] = [
                'name' => 'eZSESSID',
            ];
        }

        foreach ($adminSiteAccessNames as $adminSiteAccessName) {
            if ($adminSiteAccessName === self::NGADMINUI_SITEACCESS_NAME) {
                $settings['ezpublish']['system'][$adminSiteAccessName]['design'] = $adminSiteAccessName;
            }

            if ($adminSiteAccessName === self::LEGACY_ADMIN_SITEACCESS_NAME) {
                $settings['ez_publish_legacy']['system'][$adminSiteAccessName]['legacy_mode'] = true;
            }

            $settings['ezpublish']['system'][$adminSiteAccessName]['languages'] = $adminSiteAccessLanguages;
            if ($adminSiteAccessName !== self::LEGACY_ADMIN_SITEACCESS_NAME) {
                $settings['ezpublish']['system'][$adminSiteAccessName]['session'] = [
                    'name' => 'eZSESSID',
                ];
            }
        }

        file_put_contents(
            $this->container->getParameter('kernel.project_dir') . '/' . $this->container->getParameter('kernel.name') . '/config/ezplatform_siteaccess.yml',
            Yaml::dump($settings, 7)
        );

        $this->generateServerConfig();

        $output->writeln(
            [
                '',
                'Generated <comment>ezplatform_siteaccess.yml</comment> configuration file!',
            ]
        );
    }