Jump to content
WebWorker

New Enom Name Spinner

Recommended Posts

Here is template code to use Enom's Namespinner on your adddomain.tpl

 

Features:

  • Only displays when ordering a new domain name
  • Uses live pricing from your database
  • Formatted to match WHMCS's bulk domain checker layout
  • Uses SSL connection to enom for better securrity
  • Does not suggest unavailable domain names

 

Limitations:

  • Requires PHP5, cUrl and SimpleXML
  • Will not output anything if there was an error communicating with Enom
  • Because of the complexity of pulling encrypted passwords from WHMCS's database, you still need to put your Enom username and password into the appropriate variables.

 

Installing:

Insert this code between the line:

<p align="center"><input type="submit" value="{$LANG.addtocart}" /></p>

and

</form>

 

The code to insert:

{if $domain neq "transfer"}
{php}
	/**
	 * @version 1.0
	 * @since WHMCS 3.8
	 * @copyright 2009 http://ideamesh.com This script is owned and licensed by Ideamesh, Inc.
	 * You may use this script in commercial applications, however you may not resell
	 * this script without permission of Ideamesh, Inc.<br>
	 * Please contact (sales [at] ideamesh [dot] com) for more information
	 */

	// Extract Smarty variables
	extract($this->_tpl_vars);

	//Edit these to your actual enom username and password
	$enomid = "enomuser";
	$enompw = "enompass";

	//Max number of spins to generate
	$maxspins = 20;

	//Choose which options to show in the spin results
	$showdotcom = true;
	$showdotnet = true;
	$showdotcc = false;
	$showdottv = false;

	//Set this to "True" for blocking sensitive content or "False" to allow sensitive content
	$sensitivecontent = "True";

	//Setup the namespinner url
	$namespinnerurl = "https://reseller.enom.com/interface.asp?command=namespinner&uid=".$enomid."&pw=".$enompw."&SLD=".$sld."&TLD=".$tld."&SensitiveContent=".$sensitivecontent."&MaxResults=".$maxspins."&ResponseType=XML";

	// Use cURL to get the XML response
	$ch = curl_init($namespinnerurl);
	curl_setopt($ch, CURLOPT_HEADER, false);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	$xml = curl_exec($ch);
	curl_close($ch);

	if ($xml) {
		$spinnerresults = new SimpleXmlElement($xml, LIBXML_NOCDATA);

		if ($spinnerresults->ErrCount == 0) {
			for($i=0; $i<$maxspins; $i++){
				if ($showdotcom && (string)$spinnerresults->namespin->domains->domain[$i]['com'] == "y")
					$spinner[] = array(
						'domain' => (string)$spinnerresults->namespin->domains->domain[$i]['name'].".com",
						'sld' => (string)$spinnerresults->namespin->domains->domain[$i]['name'],
						'tld' => '.com');
				if ($showdotnet && (string)$spinnerresults->namespin->domains->domain[$i]['net'] == "y")
					$spinner[] = array(
						'domain' => (string)$spinnerresults->namespin->domains->domain[$i]['name'].".net",
						'sld' => (string)$spinnerresults->namespin->domains->domain[$i]['name'],
						'tld' => '.net');
				if ($showdotcc && (string)$spinnerresults->namespin->domains->domain[$i]['cc'] == "y")
					$spinner[] = array(
						'domain' => (string)$spinnerresults->namespin->domains->domain[$i]['name'].".cc",
						'sld' => (string)$spinnerresults->namespin->domains->domain[$i]['name'],
						'tld' => '.cc');
				if ($showdottv && (string)$spinnerresults->namespin->domains->domain[$i]['tv'] == "y")
					$spinner[] = array(
						'domain' => (string)$spinnerresults->namespin->domains->domain[$i]['name'].".tv",
						'sld' => (string)$spinnerresults->namespin->domains->domain[$i]['name'],
						'tld' => '.tv');
			}
			$gotnamespinner = true;
		} else {
			$gotnamespinner = false;
		}
	} else {
		$gotnamespinner = false;
	}

	//Get domain pricing for .com, .net, .cc and .tv
	$sql = "SELECT extension, register, registrationperiod FROM tbldomainpricing WHERE extension in ('.com', '.net', '.cc', '.tv');";
	$query = mysql_query ($sql);
	while ($row = @mysql_fetch_array ($query, MYSQL_ASSOC)) {
		$domainprices[$row['extension']][$row['registrationperiod']] = $row['register'];
	}

	//Send some variables back to the template
	$this->assign('spinner', $spinner);
	$this->assign('gotnamespinner', $gotnamespinner);
	$this->assign('domainprices', $domainprices);
{/php}

{if $gotnamespinner}
	<p class="cartsubheading">We also recommend</p>

	<table class="clientareatable" style="width:90%;" align="center" cellspacing="1">
	<tr class="clientareatableheading"><td>{$LANG.domainname}</td><td>{$LANG.domainstatus}</td><td>{$LANG.domainmoreinfo}</td></tr>
	{foreach key=num item=result from=$spinner}
		<tr class="clientareatableactive">
			<td width="33%">{$result.domain}</td>
			<td width="33%" class="domaincheckeravailable"><input type="checkbox" name="domains[]" value="{$result.domain|lower}"{if $result.domain|lower|in_array:$domains} checked{/if} /> {$LANG.domainavailable}</td>
			<td width="33%"><select name="domainsregperiod[{$result.domain|lower}]">
				{assign var=thistld value=$result.tld}
				{foreach key=years item=regoption from=$domainprices.$thistld}
					<option value="{$years}">{$years} {$LANG.orderyears} @ {$currencysymbol}{$regoption} {$currency}</option>
				{/foreach}</select>
			</td>
		</tr>
	{/foreach}
	</table>

	<p align="center"><input type="submit" value="{$LANG.addtocart}" /></p>
{/if}
{/if}

 

Final steps:

  • Edit the variables $enomid and $enompw
  • Change $maxspins variable to adjust number of suggested names
  • Change $showdotcom, $showdotnet, $showdotcc, $showdottv to your liking

 

Try it out here: https://ideamesh.com/cart.php?a=add&domain=register

 

Hope you enjoy it! Please see my note on securing your .tpl files using .htaccess at : http://forum.whmcs.com/showthread.php?p=96394

Edited by WebWorker

Share this post


Link to post
Share on other sites

Can anyone help me figure out how to add this to the wiki? Lol

 

Every time I try to edit the contributions page, it shows a blank edit screen with none of the current content.

Edited by WebWorker

Share this post


Link to post
Share on other sites

how about putting the enom information within a regular php file and then just including that? Its a bit more secure that way that just putting it within the templates. I know i can do it and will, just figured you might want to add that for others.

Share this post


Link to post
Share on other sites
how about putting the enom information within a regular php file and then just including that? Its a bit more secure that way that just putting it within the templates. I know i can do it and will, just figured you might want to add that for others.

 

After you do are you going to share it?

Share this post


Link to post
Share on other sites

Simply create a second file called enomlogin.php and put these three lines in there between the php tags:

<?php
//Edit these to your actual enom username and password
$enomid = "enomuser";
$enompw = "enompass";
?>

 

Then replace those three lines from the template with:

include('/path/to/enomlogin.php');

Share this post


Link to post
Share on other sites

It is not working for me.

 

I have tried a domain regrwxjerj.com on your demo link and it works fine I have tried the same on mine and no good it doesn't return anything at all.

 

I have also made sure I have the paths set correctly for the enomlogin.php

 

I do have the PHP, curl, simplexml installed.

 

I also have a custom theme could this be the problem?

I have made the changes to the adddomain.tpl in the order forms>>default folder as this is what I have set in the config.

Share this post


Link to post
Share on other sites

If you are testing on a development box you need to make sure that you have authorized it's IP address at enom for API access.

Share this post


Link to post
Share on other sites

After the line:

 

curl_close($ch);

 

Add this

 

 

echo "<pre>";
echo htmlentities($xml);
echo "</pre>";

 

To see the xml response from enom

Share this post


Link to post
Share on other sites

Hello WebWorker I have changed everything back and then added the code from your original post and it is working. So at least we know it is all good.

 

I am trying to set it up with the include and that is not working so it has to be something with the paths, I will mess with it a bit until I get the path that is correct not sure why thisone is giving me a hard time I have set the paths for a couple of other little things and no problems so I will just reproduce that.

 

Thanks again great addition.

Share this post


Link to post
Share on other sites

Now it would be great if we could get the output "We also recommend" results sorted by extension rather than alphabetically.

Share this post


Link to post
Share on other sites

You can use the php command getcwd() to see where the script thinks it currently is and adjust the path relative to that. Otherwise do the full path /home/username/public_html/whmcs/enomlogin.php

Share this post


Link to post
Share on other sites

I found my problem I added

$showdotinfo = true;

and messed up the

if ($showdotcom && (string)$spinnerresults->

part stupid mistake on my part but once I fixed it all is working just fine path is all good.

Share this post


Link to post
Share on other sites

Enom only gives results for the four TLD's I provided in the code. You won't be able to add extra TLD's unless you figure out some other namespinner code.

Share this post


Link to post
Share on other sites
Enom only gives results for the four TLD's I provided in the code. You won't be able to add extra TLD's unless you figure out some other namespinner code.

 

OK

 

 

It is working just fine now so all is good.

 

Is there anyway to get results sorted by extension?

Share this post


Link to post
Share on other sites

New features:

  • Ability to sort multiple ways
  • Added debug mode variable

 

Recommended Install Steps

  1. Create a new .tpl file in your orderforms template called namespinner.tpl
  2. In adddomain.tpl add the line : {include file="orderforms/cart/namespinner.tpl"} directly before before the last </form> tag
  3. In configureproductdomain.tpl add the line : {include file="orderforms/cart/namespinner.tpl"} directly before before the last </form> tag
  4. Block tpl access from the web

 

{if $domain neq "transfer"}
{php}
	/**
	 * @version 1.1
	 * @since WHMCS 3.8
	 * @copyright 2009 http://ideamesh.com This script is owned and licensed by Ideamesh, Inc.
	 * You may use this script in commercial applications, however you may not resell
	 * this script without permission of Ideamesh, Inc.<br>
	 * Please contact (sales [at] ideamesh [dot] com) for more information
	 */

	//Set to true to get debug messages
	$debug = false;

	//Edit these to your actual enom username and password
	$enomid = "enomusername";
	$enompw = "enompassword";

	//Max number of spins to generate
	$maxspins = 20;

	//Choose which options to show in the spin results
	//Enom only will return .com, .net, .cc and .tv results that's why these were chosen
	$showdotcom = true;
	$showdotnet = true;
	$showdotcc = false;
	$showdottv = false;

	//Can be one of these values ("tld"|"sld"|"score")
	$sort1 = "score";
	$sort2 = "sld";
	//Can be one of these values (SORT_ASC|SORT_DESC)
	$sort1order = SORT_DESC;
	$sort2order = SORT_ASC;

	//Set this to "True" for blocking sensitive content or "False" to allow sensitive content
	$sensitivecontent = "True";

	// Extract Smarty variables
	extract($this->_tpl_vars);

	//Do not edit this. We're setting up the URL to retrieve the spins
	$namespinnerurl = "https://reseller.enom.com/interface.asp?command=namespinner&uid=".$enomid."&pw=".$enompw."&SLD=".$sld."&TLD=".$tld."&SensitiveContent=".$sensitivecontent."&MaxResults=".$maxspins."&ResponseType=XML";

	// Use cURL to get the XML response
	$ch = curl_init($namespinnerurl);
	curl_setopt($ch, CURLOPT_HEADER, false);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	$xml = curl_exec($ch);
	curl_close($ch);

	if ($xml) {
		$spinnerresults = new SimpleXmlElement($xml, LIBXML_NOCDATA);

		if ($spinnerresults->ErrCount == 0) {
			for ($i=0; $i<$maxspins; $i++) {
				if ($showdotcom && (string)$spinnerresults->namespin->domains->domain[$i]['com'] == "y")
					$spinner[] = array(
						'domain' => (string)$spinnerresults->namespin->domains->domain[$i]['name'].".com",
						'netscore' => (int)$spinnerresults->namespin->domains->domain[$i]['comscore'],
						'tld' => '.com');
				if ($showdotnet && (string)$spinnerresults->namespin->domains->domain[$i]['net'] == "y")
					$spinner[] = array(
						'domain' => (string)$spinnerresults->namespin->domains->domain[$i]['name'].".net",
						'netscore' => (int)$spinnerresults->namespin->domains->domain[$i]['netscore'],
						'tld' => '.net');
				if ($showdotcc && (string)$spinnerresults->namespin->domains->domain[$i]['cc'] == "y")
					$spinner[] = array(
						'domain' => (string)$spinnerresults->namespin->domains->domain[$i]['name'].".cc",
						'netscore' => (int)$spinnerresults->namespin->domains->domain[$i]['ccscore'],
						'tld' => '.cc');
				if ($showdottv && (string)$spinnerresults->namespin->domains->domain[$i]['tv'] == "y")
					$spinner[] = array(
						'domain' => (string)$spinnerresults->namespin->domains->domain[$i]['name'].".tv",
						'netscore' => (int)$spinnerresults->namespin->domains->domain[$i]['tvscore'],
						'tld' => '.tv');
			}
			$gotnamespinner = true;
		} else {
			$gotnamespinner = false;
		}
	} else {
		if ($debug) echo "Cannot retrieve XML file. Please check your firewall settings";
		$gotnamespinner = false;
	}

	if ($debug) {
		echo "<pre>";
		echo htmlentities($xml);
		echo "</pre>";
	}

	//Get domain pricing for .com, .net, .cc and .tv
	if ($gotnamespinner) {
		$sql = "SELECT extension, register, registrationperiod FROM tbldomainpricing WHERE extension in ('.com', '.net', '.cc', '.tv');";
		$query = mysql_query ($sql);
		while ($row = @mysql_fetch_array ($query, MYSQL_ASSOC)) {
			$domainprices[$row['extension']][$row['registrationperiod']] = $row['register'];
		}
	}

	// Setup for the sorting
	foreach ($spinner as $key => $row) {
		$spin['sld'][$key]  = $row['domain'];
		$spin['score'][$key] = $row['netscore'];
		$spin['tld'][$key] = $row['tld'];
	}

	array_multisort($spin[$sort1], $sort1order, $spin[$sort2], $sort2order, $spinner);

	//Send some variables back to the template
	$this->assign('spinner', $spinner);
	$this->assign('gotnamespinner', $gotnamespinner);
	$this->assign('domainprices', $domainprices);
{/php}

{if $gotnamespinner}
	<p class="cartsubheading">We also recommend</p>

	<table class="clientareatable" style="width:90%;" align="center" cellspacing="1">
	<tr class="clientareatableheading"><td>{$LANG.domainname}</td><td>{$LANG.domainstatus}</td><td>{$LANG.domainmoreinfo}</td></tr>
	{foreach key=num item=result from=$spinner}
		<tr class="clientareatableactive">
			<td width="33%">{$result.domain}</td>
			<td width="33%" class="domaincheckeravailable"><input type="checkbox" name="domains[]" value="{$result.domain|lower}"{if $result.domain|lower|in_array:$domains} checked{/if} /> {$LANG.domainavailable}</td>
			<td width="33%"><select name="domainsregperiod[{$result.domain|lower}]">
				{assign var=thistld value=$result.tld}
				{foreach key=years item=regoption from=$domainprices.$thistld}
					<option value="{$years}">{$years} {$LANG.orderyears} @ {$currencysymbol}{$regoption} {$currency}</option>
				{/foreach}</select>
			</td>
		</tr>
	{/foreach}
	</table>

	<p align="center"><input type="submit" value="{$LANG.addtocart}" /></p>
{/if}
{/if}

Edited by WebWorker

Share this post


Link to post
Share on other sites
New features:

  • Ability to sort multiple ways
  • Added debug mode variable

nice - think I'll add the sort by "rank" to our version instead of them being strict alphabetical - thank you for the code :D

Share this post


Link to post
Share on other sites

The sorting by "score" and then "sld" I left in the code is my favorite way. I think it looks better and gives better suggestions.

Share this post


Link to post
Share on other sites

No worries. Shame I'm not a PHP programmer (I'm from the ColdFusion side of the fence) as I would be doing the same :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

By using this site, you agree to our Terms of Use & Guidelines