Jump to content

Domain orders forms getSld() returns odd results


nahanil

Recommended Posts

Referring to the method getSld() in <Blesta 4.2.2>/plugins/order/lib/order_types/domain/order_type_domain.php

This method doesn't handle domain searches as gracefully as it could.

Search: www.something.com (.com checkbox selected)

  • something.com
  • somethingwww..com

Search: www.something (.com checkbox selected)

  • www.com

Search: something.com (.com checkbox selected)

  • something.com

Search: something (.com checkbox selected)

  • something.com

 

I'm not sure how this could be rectified by changing the existing regex, but I've found something like the following to handle all the above inputs to return something sensible

	function getSld($domain) {
		$parts = explode(".", $domain);
		if (count($parts) == 1) {
			return $parts[0];
		}
		
		return $parts[0] == "www" ? $parts[1] : $parts[0];
	}

	// Mentioned test cases
	foreach ([
		'www.something.com', 
		'www.something', 
		'something.com', 
		'something'] as $search) {
	
		echo "$search: ", getSld($search), "<br>";
	}

	/* Output
	www.something.com: something
	www.something: something
	something.com: something
	something: something
	*/

 

Edited by texh
Specify Blesta version
Link to comment
Share on other sites

  • 4 weeks later...
  • Tyson locked this topic
Guest
This topic is now closed to further replies.
×
×
  • Create New...