/*!
\static
\return Gives all knows bases for available sitedesign folders.
176797
static function allDesignBases( $siteAccess = false )
    {
        // in memory caching
        if ( $siteAccess )
        {
            if ( isset( $GLOBALS['eZTemplateDesignResourceSiteAccessBases'] ) )
            {
                if ( isset( $GLOBALS['eZTemplateDesignResourceSiteAccessBases'][$siteAccess] ) )
                {
                    return $GLOBALS['eZTemplateDesignResourceSiteAccessBases'][$siteAccess];
                }
            }
            else
            {
                $GLOBALS['eZTemplateDesignResourceSiteAccessBases'] = array();
            }
        }
        else
        {
            if ( isset( $GLOBALS['eZTemplateDesignResourceBases'] ) )
            {
                return $GLOBALS['eZTemplateDesignResourceBases'];
            }
        }

        if ( eZINI::instance( 'site.ini' )->variable( 'DesignSettings', 'DesignLocationCache' ) === 'enabled' )
        {
            // Using current SA if none given
            $siteAccessName = $siteAccess !== false ? $siteAccess : $GLOBALS['eZCurrentAccess']['name'];

            $cachePath = eZSys::cacheDirectory()
                         . '/'
                         . self::DESIGN_BASE_CACHE_NAME
                         . md5( $siteAccessName )
                         . '.php';

            $clusterFileHandler = eZClusterFileHandler::instance( $cachePath );

            if( $clusterFileHandler->fileExists( $cachePath ) )
            {
                $designBaseList = unserialize( $clusterFileHandler->fetchContents() );

                self::savesMemoryCache( $designBaseList, $siteAccess );
            }
            else
            {
                // find design locations
                $designBaseList = self::findDesignBase( eZINI::instance( 'file.ini' ), $siteAccess );

                // stores it on the disk
                $clusterFileHandler->fileStoreContents( $cachePath,
                                                        serialize( $designBaseList ),
                                                        'designbases',
                                                        'php' );

                self::savesMemoryCache( $designBaseList, $siteAccess );
            }
        }
        else
        {
            // find design locations
            $designBaseList = self::findDesignBase( eZINI::instance( 'file.ini' ), $siteAccess );

            self::savesMemoryCache( $designBaseList, $siteAccess );
        }

        return $designBaseList;
    }
540601
protected function getDirOption($return_array = false)
    {
        if($dir = $this->option('dir')) {
            $directories = explode('/', $dir);
            if(is_array($directories) && $directories) {
                $directories = array_map(function($directory) {
                    return ucfirst(str::plural(strtolower($directory)));
                }, $directories);

                return $return_array === true ? $directories : rtrim(implode('/', $directories), '/\\') . '/';
            }
        }
    }
950637
private static function work() {

		$domain = null;
		$found  = false;

		if($request = static :: getUrl()) {

			$routes = static :: getRoutes();

			foreach($routes as $identifier => $route) {
				
				$domains = $route -> getDomain();
				$found 	 = false;

				if(null === $domains || 0 === count($domains)) {
					$found = true;
				}

				if(true === is_array($domains)) {

					foreach($domains as $host) {

						if(1 === preg_match('#'. str_replace('#', '\#', $host) .'#', Request :: parseUrl('host'))) {
							
							$found  = true;
							$domains = $host;

							break;
						}
					}
				}

				if(true === $found) {

					if(Request :: getMethod() !== null && Request :: getMethod() !== $route -> getMethod() && $route -> getMethod() !== 'any') {
						continue;
					}

					$path = $request -> trimPath();

					if(true === $route -> getStrict()) {

						if(null !== $request -> getQuery()) {
							$path .= '?' . $request -> getQuery();
						}
					}

					if(preg_match('#^'. str_replace('#', '\#', $route -> getMatch()) .'$#', $path, $match)) {

						array_shift($match);

						$match = array_map(function($tmp) {
							return ltrim($tmp, '\/');
						}, $match);

						$match = array_unique($match);
						
						static :: setRoute($route);
						static :: setParams($match);

						//Check if route is viewable
						if(true === $route -> isViewable() || null === $route -> getViewable() || true === static :: getRedirect()) {
							
							new MVC($route, $match);
							return true;
						}

						break;
					}
				}
			}
		}

		//Prevent to many redirects
		if(static :: $redirected > 50) {
			return trigger_error('Prevented to many redirects. This usually happens when there are no routes to match and the 404 will trigger the same 404 in a loop.', E_USER_ERROR);
		}

		//Update redirected
		static :: $redirected++;

		//Trigger 404 if route exists
		if(true === $found && $route = static :: $error['default'][404]) {

			$route -> viewable(true);

			$redirect = static :: redirect($route -> getIdentifier()) -> domain($domain);
			$method   = Request :: getMethod();

			if(true === is_callable([$redirect, $method])) {
				
				call_user_func_array([$redirect, $method], []);
				return true;
			}
		}

		//Else set HTTP status 404
		Response :: setStatus(404);

		return false;
	}
615970
function getFiles(base, dir = '', results = []) {
            const files = fs.readdirSync(path.join(base, dir));
            for (const file of files) {
                const relativeToBase = path.join(dir, file);
                if (fs.statSync(path.join(base, relativeToBase)).isDirectory()) {
                    getFiles(base, relativeToBase, results);
                } else {
                    results.push(relativeToBase);
                }
            }
            return results;
        }
277535
public function find($base)
    {
        $base = rtrim($base, '/');
        // Special case for a base path of /, eg. a chroot environment
        if ($base === '') {
            $base = '/';
        }

        $paths = array(array($base, 0));
        $found = array();

        $fileCallback = $this->getOption('file_callback');
        $dirCallback  = $this->getOption('dir_callback');

        while ($path = array_shift($paths)) {
            list($path, $depth) = $path;

            foreach (scandir($path) as $basename) {
                if ($basename == '.' || $basename == '..') {
                    continue;
                }

                if (is_dir("$path/$basename")) {
                    if (!$this->acceptDir($basename, "$path/$basename", $depth + 1)) {
                        continue;
                    }

                    if ($dirCallback) {
                        call_user_func(
                            $dirCallback,
                            $basename,
                            "$path/$basename",
                            $depth + 1
                        );
                    }

                    $paths[] = array("$path/$basename", $depth + 1);
                } else {
                    if (!$this->acceptFile($basename, "$path/$basename", $depth)) {
                        continue;
                    }

                    if ($fileCallback) {
                        call_user_func(
                            $fileCallback,
                            $basename,
                            "$path/$basename",
                            $depth
                        );
                    }

                    $found[] = "$path/$basename";
                }
            }
        }

        return $found;
    }
1005514
function chdir($dir)
    {
        if (!($this->bitmap & NET_SSH2_MASK_LOGIN)) {
            return false;
        }

        if ($dir[strlen($dir) - 1] != '/') {
            $dir.= '/';
        }

        // confirm that $dir is, in fact, a valid directory
        if ($this->_is_dir($dir)) {
            $this->pwd = $dir;
            return true;
        }

        $dir = $this->_realpath($dir, false);

        if ($this->_is_dir($dir)) {
            $this->pwd = $dir;
            return true;
        }

        if (!$this->_send_sftp_packet(NET_SFTP_OPENDIR, pack('Na*', strlen($dir), $dir))) {
            return false;
        }

        // see Net_SFTP::nlist() for a more thorough explanation of the following
        $response = $this->_get_sftp_packet();
        switch ($this->packet_type) {
            case NET_SFTP_HANDLE:
                $handle = substr($response, 4);
                break;
            case NET_SFTP_STATUS:
                $this->_logError($response);
                return false;
            default:
                user_error('Expected SSH_FXP_HANDLE or SSH_FXP_STATUS', E_USER_NOTICE);
                return false;
        }

        if (!$this->_send_sftp_packet(NET_SFTP_CLOSE, pack('Na*', strlen($handle), $handle))) {
            return false;
        }

        $response = $this->_get_sftp_packet();
        if ($this->packet_type != NET_SFTP_STATUS) {
            user_error('Expected SSH_FXP_STATUS', E_USER_NOTICE);
            return false;
        }

        extract(unpack('Nstatus', $this->_string_shift($response, 4)));
        if ($status != NET_SFTP_STATUS_OK) {
            $this->_logError($response, $status);
            return false;
        }

        $this->_save_dir($dir);

        $this->pwd = $dir;
        return true;
    }
378454
static function designSetting( $type = 'standard' )
    {
        if ( $type != 'standard' and
             $type != 'site' )
        {
            eZDebug::writeWarning( "Cannot retrieve designsetting for type '$type'", __METHOD__ );
            return null;
        }
        if ( $type == 'site' )
        {
            if ( !empty( $GLOBALS['eZSiteBasics']['site-design-override'] ) )
            {
                return $GLOBALS['eZSiteBasics']['site-design-override'];
            }
        }
        if ( isset( $GLOBALS['eZTemplateDesignSetting'][$type] ) )
        {
            return $GLOBALS['eZTemplateDesignSetting'][$type];
        }
        $ini = eZINI::instance();
        if ( $type == 'standard' )
        {
            $GLOBALS['eZTemplateDesignSetting'][$type] = $ini->variable( "DesignSettings", "StandardDesign" );
        }
        else if ( $type == 'site' )
        {
            $GLOBALS['eZTemplateDesignSetting'][$type] = $ini->variable( "DesignSettings", "SiteDesign" );
        }
        return $GLOBALS['eZTemplateDesignSetting'][$type];
    }
538102
function _nlist_helper($dir, $recursive, $relativeDir)
    {
        $files = $this->_list($dir, false);

        if (!$recursive || $files === false) {
            return $files;
        }

        $result = array();
        foreach ($files as $value) {
            if ($value == '.' || $value == '..') {
                if ($relativeDir == '') {
                    $result[] = $value;
                }
                continue;
            }
            if (is_array($this->_query_stat_cache($this->_realpath($dir . '/' . $value)))) {
                $temp = $this->_nlist_helper($dir . '/' . $value, true, $relativeDir . $value . '/');
                $result = array_merge($result, $temp);
            } else {
                $result[] = $relativeDir . $value;
            }
        }

        return $result;
    }
359360
protected function checkSite()
    {
        $sites = $this->fetchSites(fp_env('ACACHA_FORGE_SERVER'));
        return in_array(fp_env('ACACHA_FORGE_SITE'), collect($sites)->pluck('id')->toArray());
    }
517072
protected function getSite($sites, $site_id)
    {
        $site_found = collect($sites)->filter(function ($site) use ($site_id) {
            return $site->id === $site_id;
        })->first();

        if ($site_found) {
            return $site_found;
        }
        return null;
    }
1143671
public function findAll($name, $reload = false, $reversed = false, $type = 'all')
	{
		$name = trim($name, '\\/');
		$scope = 'all::'.$type;
		$asHandlers = $this->returnHandlers;
		$group = '__DEFAULT__';
		$query = $name;

		if ($this->nextAsHandlers !== null)
		{
			$asHandlers = $this->nextAsHandlers;
			$this->nextAsHandlers = null;
		}

		if (strpos($query, '::') !== false)
		{
			list($group, $query) = explode('::', $query);
		}

		if ( ! isset($this->paths[$group]))
		{
			return [];
		}

		if ($type !== 'dir')
		{
			$query = $this->normalizeFileName($query);
		}

		if ( ! $reload and $cached = $this->findCached($scope, $name, $reversed))
		{
			return $cached;
		}

		$used = [];
		$found = [];
		$paths = $reversed ? array_reverse($this->paths[$group]) : $this->paths[$group];

		foreach ($paths as $path)
		{
			if ($type !== 'dir' and is_file($path.$query))
			{
				$found[] = $asHandlers ? new File($path.$query) : $path.$query;
				$used[] = $path;
			}
			elseif ($type !== 'file' and is_dir($path.$query))
			{
				$found[] = $asHandlers ? new Directory($path.$query, $this->returnHandlers) : $path.$query;
				$used[] = $path;
			}
		}

		// Store the paths in cache
		$this->cache($scope, $name, $reversed, $found, $used);

		return $found;
	}
924436
static function bootstrap($bootstrap)
  {
    $basepath = realpath(dirname($bootstrap));

    $fs = new Filesystem;

    $pluginSrcFile = $basepath.'/src/plugin.php';

    require_once $pluginSrcFile;
    
    $source = $fs->get($pluginSrcFile);
    
    $pluginClass = static::getFirstPluginClassName($source);
    
    // now check to see if we've been here before...
    if (!empty(static::$plugins[$pluginClass])) {
      return static::$plugins[$pluginClass];
    }

    // the plugin will have already been bootstrapped by
    // the time we get here IF the autoload file exists;
    // if it doesn't, setup a fallback class loader
    if (!file_exists($composer = $basepath.'/vendor/autoload.php')) {
      
      spl_autoload_register(function($name) use ($fs, $basepath) {

        $src = $basepath.'/src';
        $files = $fs->glob($src.'/**/*.php');
        
        static $classmap;

        // build the classmap
        if ($classmap === null) {
          $classmap = [];
          foreach($files as $file) {
            $contents = $fs->get($file);
            $namespace = '';
            if (preg_match('/namespace\s+(.*?);/i', $contents, $matches)) {
              $namespace = $matches[1];
            }
            if (preg_match_all('/class\s+([\w\_]+).*?{/i', $contents, $matches)) {
              foreach($matches[1] as $className) {
                $classmap["{$namespace}\\{$className}"] = $file;
              }
            }
          }
        }

        // if we found a match, load it
        if (!empty($classmap[$name])) {
          require_once $classmap[$name];
        }
      });

    }

    $plugin = new $pluginClass($bootstrap);

    static::$plugins[$pluginClass] = $plugin;
    static::$plugins[$plugin->getSlug()] = $plugin;
    
    return static::$plugins[$pluginClass];
  }
1111316
public static function getDirectories($base_directory, $context, $environment)
    {
        $bootstrap_directories = array();

        if (BBApplication::DEFAULT_CONTEXT !== $context) {
            if (BBApplication::DEFAULT_ENVIRONMENT !== $environment) {
                $bootstrap_directories[] = implode(DIRECTORY_SEPARATOR, array(
                    $base_directory, $context, 'Config', $environment,
                ));
            }

            $bootstrap_directories[] = implode(DIRECTORY_SEPARATOR, array($base_directory, $context, 'Config'));
        }

        if (BBApplication::DEFAULT_ENVIRONMENT !== $environment) {
            $bootstrap_directories[] = implode(DIRECTORY_SEPARATOR, array(
                $base_directory, 'Config', $environment,
            ));
        }

        $bootstrap_directories[] = $base_directory.DIRECTORY_SEPARATOR.'Config';

        return $bootstrap_directories;
    }
246071
function match_field_groups( $return, $options )
	{
		
		// vars
		$defaults = array(
			'post_id' => 0,
			'post_type' => 0,
			'page_template' => 0,
			'page_parent' => 0,
			'page_type' => 0,
			'post_category' => array(),
			'post_format' => 0,
			'taxonomy' => array(),
			'ef_taxonomy' => 0,
			'ef_user' => 0,
			'ef_media' => 0,
			'lang' => 0,
			'ajax' => false
		);
		
		
		// merge in $options
		$options = array_merge($defaults, $options);
		
		
		// Parse values
		$options = apply_filters( 'acf/parse_types', $options );
		

		// WPML
		if( defined('ICL_LANGUAGE_CODE') )
		{
			$options['lang'] = ICL_LANGUAGE_CODE;
			
			//global $sitepress;
			//$sitepress->switch_lang( $options['lang'] );
		}
		
		
		// find all acf objects
		$acfs = apply_filters('acf/get_field_groups', array());

		
		// blank array to hold acfs
		$return = array();
		
		
		if( $acfs )
		{
			foreach( $acfs as $acf )
			{
				// load location
				$acf['location'] = apply_filters('acf/field_group/get_location', array(), $acf['id']);

				
				// vars
				$add_box = false;
				
				
				foreach( $acf['location'] as $group_id => $group )
				{
					// start of as true, this way, any rule that doesn't match will cause this varaible to false
					$match_group = true;
					
					if( is_array($group) )
					{
						foreach( $group as $rule_id => $rule )
						{
							// Hack for ef_media => now post_type = attachment
							if( $rule['param'] == 'ef_media' )
							{
								$rule['param'] = 'post_type';
								$rule['value'] = 'attachment';
							}
							
							
							// $match = true / false
							$match = apply_filters( 'acf/location/rule_match/' . $rule['param'] , false, $rule, $options );
							
							if( !$match )
							{
								$match_group = false;
							}
							
						}
					}
					
					
					// all rules must havematched!
					if( $match_group )
					{
						$add_box = true;
					}
					
				}
		
				
				// add ID to array	
				if( $add_box )
				{
					$return[] = $acf['id'];
					
				}
				
			}
		}
		
	
		return $return;
	}
1263912
public function all()
    {
        $list = [];

        /** @var UniformResourceLocator $locator */
        $locator = $this->grav['locator'];

        $iterator = $locator->getIterator('themes://');

        /** @var \DirectoryIterator $directory */
        foreach ($iterator as $directory) {
            if (!$directory->isDir() || $directory->isDot()) {
                continue;
            }

            $theme = $directory->getFilename();
            $result = $this->get($theme);

            if ($result) {
                $list[$theme] = $result;
            }
        }
        ksort($list);

        return $list;
    }
1081411
static function defaultValue( $url, $returnDefault )
    {
        if ( $returnDefault )
        {
            $mime = eZMimeType::defaultMimeType();
            $mime['url'] = $url;
            $suffixPos = strpos( $url, '.' );

            if ( $suffixPos !== false )
            {
                $mime['suffix'] = substr( $url, $suffixPos + 1 );
                $mime['dirpath'] = dirname( $url );
                $mime['basename'] = basename( $url, '.' . $mime['suffix'] );
                $mime['filename'] = $mime['basename'] . '.' . $mime['suffix'];
            }
            else
            {
                $mime['basename'] = $url;
                $mime['suffix'] = false;
            }
            $mime['is_valid'] = false;
            return $mime;
        }
        else
            return false;
    }
767716
static function getIni( $siteAccess, $settingFile = 'site.ini' )
    {
        // return global if siteaccess is same as requested or false
        if ( isset( $GLOBALS['eZCurrentAccess']['name'] )
          && $GLOBALS['eZCurrentAccess']['name'] === $siteAccess )
        {
            return eZINI::instance( $settingFile );
        }
        else if ( !$siteAccess )
        {
            return eZINI::instance( $settingFile );
        }

        // create a site ini instance using $useLocalOverrides = true
        $siteIni = new eZINI( 'site.ini', 'settings', null, null, true );

        // create a dummy access definition (not used as long as $siteIni is sent to self::load() )
        $access = array( 'name' => $siteAccess,
                         'type' => eZSiteAccess::TYPE_STATIC,
                         'uri_part' => array() );

        // Load siteaccess but on our locale instance of site.ini only
        $access = self::load( $access, $siteIni );

        // if site.ini, return with no further work needed
        if ( $settingFile === 'site.ini' )
        {
            return $siteIni;
        }

        // load settings file with $useLocalOverrides = true
        $ini = new eZINI( $settingFile,'settings', null, null, true );
        $ini->setOverrideDirs( $siteIni->overrideDirs( false ) );
        $ini->load();

        return $ini;
    }