HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux wordpress-ubuntu-s-2vcpu-4gb-fra1-01 5.4.0-169-generic #187-Ubuntu SMP Thu Nov 23 14:52:28 UTC 2023 x86_64
User: root (0)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/azvo/wp-content/plugins/sitepress-multilingual-cms/classes/setup/endpoints/AddressStep.php
<?php

namespace WPML\Setup\Endpoint;

use WPML\Ajax\IHandler;
use WPML\Collect\Support\Collection;
use WPML\Core\LanguageNegotiation;
use WPML\FP\Either;
use WPML\FP\Fns;
use WPML\FP\Logic;
use WPML\FP\Obj;
use WPML\FP\Relation;
use WPML\FP\Right;
use WPML\FP\Str;
use function WPML\Container\make;
use function WPML\FP\chain;
use function WPML\FP\pipe;
use function WPML\FP\System\sanitizeString;

class AddressStep implements IHandler {

	public function run( Collection $data ) {

		$isDomainMode    = Relation::propEq( 'mode', LanguageNegotiation::DOMAIN_STRING );
		$isDirectoryMode = Relation::propEq( 'mode', LanguageNegotiation::DIRECTORY_STRING );
		$otherWise       = Fns::always( true );

		$handleModes = Logic::cond( [
			[ $isDomainMode, $this->handleDomains() ],
			[ $isDirectoryMode, $this->validateSubdirectoryUrls() ],
			[ $otherWise, Fns::identity() ]
		] );

		return Right::of( $data )
		            ->chain( $handleModes )
		            ->map( Obj::prop( 'mode' ) )
		            ->map( sanitizeString() )
		            ->map( LanguageNegotiation::saveMode() )
		            ->map( Fns::always( 'ok' ) );
	}

	/**
	 * @return callable(Collection) : Either Left(unavailable) | Right(data)
	 */
	private function validateDomains() {
		return function ( $data ) {
			return $this->validate( wpml_collect( $data->get( 'domains' ) ), $data );
		};
	}

	/**
	 * @return callable(Collection) : Either Left(unavailable) | Right(data)
	 */
	private function handleDomains() {
		$saveDomains = Fns::tap( pipe( Obj::prop( 'domains' ), LanguageNegotiation::saveDomains() ) );

		return pipe( $this->validateDomains(), chain( $saveDomains ) );
	}

	/**
	 * @return callable(Collection) : Either Left(unavailable) | Right(data)
	 */
	private function validateSubdirectoryUrls() {
		return function ( Collection $data ) {
			return $this->validate( \wpml_collect( $data->get( 'domains' ) )->map(  Fns::nthArg( 1 ) ), $data );
		};
	}

	/**
	 * @param Collection $domains
	 * @param Collection $data
	 *
	 * @return callable|\WPML\FP\Left|Right
	 */
	private function validate( Collection $domains, Collection $data ) {
		$unavailableUrls = $domains->reject( $this->getValidator( $data ) )->keys()->toArray();

		return $unavailableUrls
			? Either::left( $unavailableUrls )
			: Either::of( $data );
	}

	/**
	 * @param Collection $data
	 *
	 * @return callable(string) : bool
	 */
	private function getValidator( Collection $data ) {
		$validator = Relation::propEq( 'mode', LanguageNegotiation::DIRECTORY_STRING, $data )
			? [ make( \WPML_Lang_URL_Validator::class ), 'validate_langs_in_dirs' ]
			: [ make( \WPML_Language_Domain_Validation::class ), 'is_valid' ];

		return Obj::propOr( false, 'ignoreInvalidUrls', $data )
			? Fns::always( true )
			: Fns::unary( $validator );
	}
}