WebWorker Posted March 15, 2009 Share Posted March 15, 2009 (edited) 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 March 15, 2009 by WebWorker 0 Quote Link to comment Share on other sites More sharing options...
WebWorker Posted March 15, 2009 Author Share Posted March 15, 2009 (edited) 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 March 15, 2009 by WebWorker 0 Quote Link to comment Share on other sites More sharing options...
MACscr Posted March 15, 2009 Share Posted March 15, 2009 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. 0 Quote Link to comment Share on other sites More sharing options...
Operator Posted March 15, 2009 Share Posted March 15, 2009 Here you go m8 made a wiki page for you: Contribution:Enom_Name_Spinner Should you wish to edit it just go to that page and click the edit button up top. 0 Quote Link to comment Share on other sites More sharing options...
yamaharr1 Posted March 16, 2009 Share Posted March 16, 2009 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? 0 Quote Link to comment Share on other sites More sharing options...
WebWorker Posted March 16, 2009 Author Share Posted March 16, 2009 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'); 0 Quote Link to comment Share on other sites More sharing options...
yamaharr1 Posted March 17, 2009 Share Posted March 17, 2009 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. 0 Quote Link to comment Share on other sites More sharing options...
WebWorker Posted March 17, 2009 Author Share Posted March 17, 2009 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. 0 Quote Link to comment Share on other sites More sharing options...
yamaharr1 Posted March 17, 2009 Share Posted March 17, 2009 Not on a development box, ENOM IP authorized also. 0 Quote Link to comment Share on other sites More sharing options...
WebWorker Posted March 17, 2009 Author Share Posted March 17, 2009 After the line: curl_close($ch); Add this echo "<pre>"; echo htmlentities($xml); echo "</pre>"; To see the xml response from enom 0 Quote Link to comment Share on other sites More sharing options...
yamaharr1 Posted March 17, 2009 Share Posted March 17, 2009 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. 0 Quote Link to comment Share on other sites More sharing options...
yamaharr1 Posted March 17, 2009 Share Posted March 17, 2009 Now it would be great if we could get the output "We also recommend" results sorted by extension rather than alphabetically. 0 Quote Link to comment Share on other sites More sharing options...
WebWorker Posted March 17, 2009 Author Share Posted March 17, 2009 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 0 Quote Link to comment Share on other sites More sharing options...
yamaharr1 Posted March 17, 2009 Share Posted March 17, 2009 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. 0 Quote Link to comment Share on other sites More sharing options...
WebWorker Posted March 17, 2009 Author Share Posted March 17, 2009 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. 0 Quote Link to comment Share on other sites More sharing options...
yamaharr1 Posted March 17, 2009 Share Posted March 17, 2009 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? 0 Quote Link to comment Share on other sites More sharing options...
WebWorker Posted March 17, 2009 Author Share Posted March 17, 2009 (edited) New features: Ability to sort multiple ways Added debug mode variable Recommended Install Steps Create a new .tpl file in your orderforms template called namespinner.tpl In adddomain.tpl add the line : {include file="orderforms/cart/namespinner.tpl"} directly before before the last </form> tag In configureproductdomain.tpl add the line : {include file="orderforms/cart/namespinner.tpl"} directly before before the last </form> tag 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 March 17, 2009 by WebWorker 0 Quote Link to comment Share on other sites More sharing options...
yamaharr1 Posted March 23, 2009 Share Posted March 23, 2009 Nice Job is working perfect 0 Quote Link to comment Share on other sites More sharing options...
othellotech Posted March 23, 2009 Share Posted March 23, 2009 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 0 Quote Link to comment Share on other sites More sharing options...
WebWorker Posted March 25, 2009 Author Share Posted March 25, 2009 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. 0 Quote Link to comment Share on other sites More sharing options...
openmind Posted March 25, 2009 Share Posted March 25, 2009 Excellent plugin, anyway I can make a donation? 0 Quote Link to comment Share on other sites More sharing options...
WebWorker Posted March 25, 2009 Author Share Posted March 25, 2009 Sure any donations are definitely appreciated and will ensure that I keep up with any bug fixes and upgrades in the future. I create a donate button here: http://ideamesh.com/donation.php 0 Quote Link to comment Share on other sites More sharing options...
openmind Posted March 26, 2009 Share Posted March 26, 2009 Done for you now 0 Quote Link to comment Share on other sites More sharing options...
WebWorker Posted March 26, 2009 Author Share Posted March 26, 2009 Thank you Phil! I'm sure as I dig more into WHMCS I will be releasing more little toys like this. 0 Quote Link to comment Share on other sites More sharing options...
openmind Posted March 27, 2009 Share Posted March 27, 2009 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 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.