Find translations from a url

@param string $url      The translation url
@return array An array with physical file paths
430253
public function find($url)
    {
        $locale   = $this->getLocale();
        $fallback = $this->getLocaleFallback();
        $locator  = $this->getObject('translator.locator.factory')->createLocator($url);

        //Find translation based on the locale
        $result = $locator->setLocale($locale)->locate($url, $locale);

        //If no translations found, try using the fallback locale
        if(empty($result) && $fallback && $fallback != $locale) {
            $result = $locator->setLocale($fallback)->locate($url, $fallback);
        }

        return $result;
    }
400087
private static function get(string $url)
    {
        $cu = curl_init();
        curl_setopt_array(
            $cu,
            [
                CURLOPT_URL            => $url,
                CURLOPT_RETURNTRANSFER => 1,
                CURLOPT_FOLLOWLOCATION => 1,
                CURLOPT_USERAGENT      => 'Torrent Parser PHP'
            ]
        );
        $response = curl_exec($cu);
        $data = json_decode($response, true) ?? [];
        return self::createCollection($data);
    }
781315
protected function parse($url) {
        // set the download file url
        $this->url = $url;

        // parse the url, to remove possible query parameters, otherwise it is not possible to fetch the extension
        $urlParsed = parse_url($url);

        // get the path info of the given name
        $pathinfo = pathinfo($urlParsed['path']);

        // get the base file name
        $this->nameOriginal = $pathinfo['filename'];

        // set the file name
        $this->extension = $pathinfo['extension'];

        // done, return the instance of this, to make chaining possible
        return $this;
    }
1067455
protected function findLanguageFiles($path)
    {
        // Loop through directories
        $dirIterator = new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS);
        $recIterator = new \RecursiveIteratorIterator($dirIterator);

        // Fetch only php files - skip others
        $phpFiles = array_values(
            array_map('current',
                iterator_to_array(
                    new \RegexIterator($recIterator, $this->phpRegex, \RecursiveRegexIterator::GET_MATCH)
                )
            )
        );

        $jsonFiles = array_values(
            array_map('current',
                iterator_to_array(
                    new \RegexIterator($recIterator, $this->jsonRegex, \RecursiveRegexIterator::GET_MATCH)
                )
            )
        );

        $files = array_merge($phpFiles, $jsonFiles);

        // Sort array by filepath
        sort($files);

        // Remove full path from items
        array_walk($files, function (&$item) use ($path) {
            $item = str_replace($path, '', $item);
        });

        // Fetch non-vendor files from filtered php files
        $nonVendorFiles = array_filter($files, function ($file) {
            return strpos($file, $this->excludePath) === false && strpos($file, '.json') === false;
        });

        // Fetch vendor files from filtered php files
        $vendorFiles = array_filter(array_diff($files, $nonVendorFiles), function ($file) {
            return strpos($file, 'json') === false;
        });

        // Fetch .json files from filtered files
        $jsonFiles = array_filter($files, function ($file) {
            return strpos($file, '.json') !== false;
        });

        return [
            'lang'   => array_values($nonVendorFiles),
            'vendor' => array_values($vendorFiles),
            'json'   => array_values($jsonFiles),
        ];
    }
540478
protected function getUrlContents(string $url): string
    {
        $request = $this->getRequest($url);

        return $this->getParsedResponse($request);
    }
830977
public function extractShortUrl(string $url):array {
		$urls = [$url];

		while($url = $this->extract($url)){
			$urls[] = $url;
		}

		return $urls;
	}
1012090
private function getFile($url)
	{
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_HEADER, false);
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
		$result = curl_exec($ch);
		curl_close($ch);

		$response = json_decode($result, TRUE);
		if (is_array($response) && count($response) > 0 && (!isset($response['status']) || $response['status'] != '404')) {
			return $response;
		}
		
		return false;
	}
767492
public function getAlternateLinks($urls)
    {
        // determine default and current values
        $webspaceKey = $this->requestAnalyzer->getWebspace()->getKey();
        $currentPortal = $this->requestAnalyzer->getPortal();

        $defaultLocale = null;
        if (null !== $currentPortal && null !== ($defaultLocale = $currentPortal->getXDefaultLocalization())) {
            $defaultLocale = $defaultLocale->getLocale();
        }

        $result = [];
        foreach ($urls as $locale => $url) {
            // url = '/' means that there is no translation for this page
            // the only exception is the homepage where the requested resource-locator is '/'
            if ('/' !== $url || '/' === $this->requestAnalyzer->getResourceLocator()) {
                if ($locale === $defaultLocale) {
                    $result[] = $this->getAlternate($url, $webspaceKey, $locale, true);
                }
                $result[] = $this->getAlternate($url, $webspaceKey, $locale);
            }
        }

        return implode(PHP_EOL, $result);
    }
1244036
protected function dropzoneAttributes($url)
    {

        $init      = new JavaScriptExpression($this->init('translationImport'));
        $validator = app(CsvValidator::class);
        $rules     = $this->getValidationRules('file', $validator);
        return [
            'container'     => 'translationImport',
            'paramName'     => 'file',
            'view'          => 'antares/translations::admin.partials._dropzone',
            'url'           => $url,
            'maxFiles'      => 1,
            'acceptedFiles' => '.csv',
            'init'          => $init] + $rules;
    }
1025229
public static function findTranslations($path, $locale)
    {
        $localePath = realpath(BASE_DIR . DIRECTORY_SEPARATOR . 'locale');
        $localePath .= DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . 'LC_MESSAGES' . DIRECTORY_SEPARATOR;

        $translations = array();
        if (file_exists($path)) {
            $d = dir($path);
            while (false !== ($dir = $d->read())) {
                GeneratorHelper::createDir($localePath);
                if (!file_exists($localePath . 'translations.po')) {
                    file_put_contents($localePath . 'translations.po', '');
                }
                $inspect_path = realpath($path . DIRECTORY_SEPARATOR . $dir);
                $cmd_php = "export PATH=\$PATH:/opt/local/bin; xgettext " .
                    $inspect_path . DIRECTORY_SEPARATOR .
                    "*.php --from-code=UTF-8 -j -L PHP --debug --force-po -o {$localePath}translations.po";
                if (is_dir($path . DIRECTORY_SEPARATOR . $dir) && preg_match('/^\./', $dir) == 0) {
                    $res = t('Revisando directorio: ') . $inspect_path;
                    $res .= t('Comando ejecutado: ') . $cmd_php;
                    $res .= shell_exec($cmd_php);
                    usleep(10);
                    $translations[] = $res;
                    $translations = array_merge($translations, self::findTranslations($inspect_path, $locale));
                }
            }
        }
        return $translations;
    }
660341
public static function googleTranslator(Url $url)
    {
        if (($value = $url->getQueryParameter('u'))) {
            return Url::create($value);
        }

        return $url;
    }
36621
public function parseUrl($url) : array
    {
        $url = (string) $url;

        $parsedUrl = $this->doParseUrl($url);

        if ($parsedUrl === []) {
            throw new InvalidArgumentException(sprintf('Invalid url %s', $url));
        }

        $parsedUrl = array_merge(self::$defaultParts, $parsedUrl);

        if (isset($parsedUrl['host'])) {
            $parsedUrl['canonical'] = implode('.', array_reverse(explode('.', $parsedUrl['host']))) . ($parsedUrl['path'] ?? '') . (isset($parsedUrl['query']) ? '?' . $parsedUrl['query'] : '');

            $parsedUrl['resource'] = $parsedUrl['path'] ?? '';

            if (isset($parsedUrl['query'])) {
                $parsedUrl['resource'] .= '?' . $parsedUrl['query'];
            }
        }

        return $parsedUrl;
    }
1225844
static public function fetchByUrl( $url, $mainTranslation = false )
    {
        $urlArray = is_array( $url ) ? $url : explode( '/', ltrim( $url, '/' ) );
        if ( !is_array( $urlArray ) || empty( $urlArray ) )
            return null;

        $parentID = 0;
        for ( $i = 0; $i < count( $urlArray ) - 1; $i++ )
        {
            /** @var eZTagsObject[] $tags */
            $tags = self::fetchList(
                array(
                    'parent_id' => $parentID,
                    'main_tag_id' => 0,
                    'keyword' => urldecode( trim( $urlArray[$i] ) )
                ),
                null,
                null,
                $mainTranslation
            );

            if ( !is_array( $tags ) || empty( $tags ) )
                return null;

            $parentID = $tags[0]->attribute( 'id' );
        }

        $tags = self::fetchList(
            array(
                'parent_id' => $parentID,
                'keyword' => urldecode( trim( $urlArray[count( $urlArray ) - 1] ) )
            ),
            null,
            null,
            $mainTranslation
        );

        if ( !is_array( $tags ) || empty( $tags ) )
            return null;

        return $tags[0];
    }
1075802
public function discover(string $url) : array
    {
        $explorer = new Explorer($this->client, $this->logger);

        return $explorer->discover($url);
    }
981514
public function parseUrl($url)
    {
        $scheme   = parse_url($url, PHP_URL_SCHEME);
        $domain   = parse_url($url, PHP_URL_HOST);
        $basename = pathinfo($url, PATHINFO_BASENAME);

        $parts = explode('.', $basename);

        if(count($parts) == 3)
        {
            $type  =  array_pop($parts);
            $format = array_pop($parts);
            $file   = array_pop($parts);
        }
        else
        {
            $type   = '*';
            $format = array_pop($parts);
            $file   = array_pop($parts);
        }

        $path = str_replace(array($scheme.'://', $scheme.':'), '', dirname($url));

        if (strpos($path, $domain.'/') === 0) {
            $path = substr($path, strlen($domain)+1);
        }

        $parts = explode('/', $path);

        $info = array(
            'type'    => $type,
            'domain'  => $domain,
            'package' => array_shift($parts),
            'path'    => implode('/', $parts),
            'file'    => $file,
            'format'  => $format ?: '*',
        );

        return $info;
    }
437947
protected function extractTranslationFromFile($path)
    {
        $result = [];
        $string = file_get_contents($path);

        foreach (array_flatten($this->config('trans_methods', [])) as $method) {
            preg_match_all($method, $string, $matches);

            foreach ($matches[1] as $k => $v) {
                if (strpos($v, '$') !== false) {
                    unset($matches[1][$k]);
                }
                if (strpos($v, '::') !== false) {
                    unset($matches[1][$k]);
                }
            }

            $result = array_merge($result, array_flip($matches[1]));
        }

        return $result;
    }
631399
public static function parse($url)
    {
        if (!strlen($url)) {
            return null;
        }
        $_urls = array_merge( @parse_url($url), array('params'=>array()) );
        if (isset($_urls['query'])) {
            parse_str($_urls['query'], $_urls['params']);
        }
        return $_urls;  
    }