<commit_before><?php
/**
 * Namesilo Module
 *
 * @package blesta
 * @subpackage blesta.components.modules.namesilo
 * @copyright Copyright (c) 2010, <NAME>, Inc.
 * @link http://www.blesta.com/ Blesta
 * @copyright Copyright (c) 2015-2018, NETLINK IT SERVICES
 * @link http://www.netlink.ie/ NETLINK
 */
class Namesilo extends Module {
	
	private static $debug_to = "root@localhost";
	
	// Namesilo response codes (array)
	private static $codes;
	
	// Pending statutes (array)
	private static $pending = array( 'in_review', 'pending' );
	
	private static $defaultModuleView;
	
	private static $api;
	
	/**
	 * Initializes the module
	 */
	public function __construct() {
		# Load config.json
		$this->loadConfig( __DIR__ . DS . "config.json" );
		# Load components required by this module
		Loader::loadComponents( $this, array ( "Input" ) );
		# Load the language required by this module
		Language::loadLang( "namesilo", null, __DIR__ . DS . "language" . DS );
		# Load configuration
		Configure::load( "namesilo", __DIR__ . DS . "config" . DS );
		# Get Namesilo response codes
		self::$codes = Configure::get( 'Namesilo.status.codes' );
		# Set default module view
		self::$defaultModuleView = "components" . DS . "modules" . DS . "namesilo" . DS;
	}

	/**
	 * Returns the name of this module
	 *
	 * @return string The common name of this module
	 */
	public function getName() {
		return Language::_( "Namesilo.name", true );
	}
	
	/**
	 * Returns the value used to identify a particular service
	 *
	 * @param stdClass $service A stdClass object representing the service
	 * @return string A value used to identify this service amongst other similar services
	 */
	public function getServiceName( $service ) {
		foreach ( $service->fields as $field ) {
			if ( $field->key == "domain" ) {
				return $field->value;
			}
		}
		return null;
	}
	
	/**
	 * Returns a noun used to refer to a module row (e.g. "Server", "VPS", "Reseller Account", etc.)
	 *
	 * @return string The noun used to refer to a module row
	 */
	public function moduleRowName() {
		return Language::_( "Namesilo.module_row", true );
	}
	
	/**
	 * Returns a noun used to refer to a module row in plural form (e.g. "Servers", "VPSs", "Reseller Accounts", etc.)
	 *
	 * @return string The noun used to refer to a module row in plural form
	 */
	public function moduleRowNamePlural() {
		return Language::_("Namesilo.module_row_plural", true);
	}
	
	/**
	 * Returns a noun used to refer to a module group (e.g. "Server Group", "Cloud", etc.)
	 *
	 * @return string The noun used to refer to a module group
	 */
	public function moduleGroupName() {
		return null;
	}
	
	/**
	 * Returns the key used to identify the primary field from the set of module row meta fields.
	 * This value can be any of the module row meta fields.
	 *
	 * @return string The key used to identify the primary field from the set of module row meta fields
	 */
	public function moduleRowMetaKey() {
		return "user";
	}
	
	/**
	 * Returns the value used to identify a particular package service which has
	 * not yet been made into a service. This may be used to uniquely identify
	 * an uncreated services of the same package (i.e. in an order form checkout)
	 *
	 * @param stdClass $package A stdClass object representing the selected package
	 * @param array $vars An array of user supplied info to satisfy the request
	 * @return string The value used to identify this package service
	 * @see Module::getServiceName()
	 */
	public function getPackageServiceName($packages, array $vars=null) {
		if (isset($vars['domain']))
			return $vars['domain'];
		return null;
	}
	
	/**
	 * Attempts to validate service info. This is the top-level error checking method. Sets Input errors on failure.
	 *
	 * @param stdClass $package A stdClass object representing the selected package
	 * @param array $vars An array of user supplied info to satisfy the request
	 * @return boolean True if the service validates, false otherwise. Sets Input errors when false.
	 */
	public function validateService($package, array $vars=null) {
        $rules = array();

        // Transfers (EPP Code)
	    if ( isset( $vars['transfer'] ) && $vars['transfer'] === '2' ) {
            $rule = [
                'auth' => [
                    'empty' => array(
                        'rule' => array("isEmpty"),
                        'negate' => true,
                        'message' => Language::_("Namesilo.!error.epp.empty", true),
                        'post_format' => "trim"
                    )
                ],
            ];
            $rules = array_merge($rules,$rule);
        }

        // .us fields
        if(isset($vars['usnc']) || isset($vars['usap'])){
            $rule = [<commit_msg>require client to enter epp code for transfers<commit_after><?php
/**
 * Namesilo Module
 *
 * @package blesta
 * @subpackage blesta.components.modules.namesilo
 * @copyright Copyright (c) 2010, Phillips Data, Inc.
 * @link http://www.blesta.com/ Blesta
 * @copyright Copyright (c) 2015-2018, NETLINK IT SERVICES
 * @link http://www.netlink.ie/ NETLINK
 */
class Namesilo extends Module {
	
	private static $debug_to = "root@localhost";
	
	// Namesilo response codes (array)
	private static $codes;
	
	// Pending statutes (array)
	private static $pending = array( 'in_review', 'pending' );
	
	private static $defaultModuleView;
	
	private static $api;
	
	/**
	 * Initializes the module
	 */
	public function __construct() {
		# Load config.json
		$this->loadConfig( __DIR__ . DS . "config.json" );
		# Load components required by this module
		Loader::loadComponents( $this, array ( "Input" ) );
		# Load the language required by this module
		Language::loadLang( "namesilo", null, __DIR__ . DS . "language" . DS );
		# Load configuration
		Configure::load( "namesilo", __DIR__ . DS . "config" . DS );
		# Get Namesilo response codes
		self::$codes = Configure::get( 'Namesilo.status.codes' );
		# Set default module view
		self::$defaultModuleView = "components" . DS . "modules" . DS . "namesilo" . DS;
	}

	/**
	 * Returns the name of this module
	 *
	 * @return string The common name of this module
	 */
	public function getName() {
		return Language::_( "Namesilo.name", true );
	}
	
	/**
	 * Returns the value used to identify a particular service
	 *
	 * @param stdClass $service A stdClass object representing the service
	 * @return string A value used to identify this service amongst other similar services
	 */
	public function getServiceName( $service ) {
		foreach ( $service->fields as $field ) {
			if ( $field->key == "domain" ) {
				return $field->value;
			}
		}
		return null;
	}
	
	/**
	 * Returns a noun used to refer to a module row (e.g. "Server", "VPS", "Reseller Account", etc.)
	 *
	 * @return string The noun used to refer to a module row
	 */
	public function moduleRowName() {
		return Language::_( "Namesilo.module_row", true );
	}
	
	/**
	 * Returns a noun used to refer to a module row in plural form (e.g. "Servers", "VPSs", "Reseller Accounts", etc.)
	 *
	 * @return string The noun used to refer to a module row in plural form
	 */
	public function moduleRowNamePlural() {
		return Language::_("Namesilo.module_row_plural", true);
	}
	
	/**
	 * Returns a noun used to refer to a module group (e.g. "Server Group", "Cloud", etc.)
	 *
	 * @return string The noun used to refer to a module group
	 */
	public function moduleGroupName() {
		return null;
	}
	
	/**
	 * Returns the key used to identify the primary field from the set of module row meta fields.
	 * This value can be any of the module row meta fields.
	 *
	 * @return string The key used to identify the primary field from the set of module row meta fields
	 */
	public function moduleRowMetaKey() {
		return "user";
	}
	
	/**
	 * Returns the value used to identify a particular package service which has
	 * not yet been made into a service. This may be used to uniquely identify
	 * an uncreated services of the same package (i.e. in an order form checkout)
	 *
	 * @param stdClass $package A stdClass object representing the selected package
	 * @param array $vars An array of user supplied info to satisfy the request
	 * @return string The value used to identify this package service
	 * @see Module::getServiceName()
	 */
	public function getPackageServiceName($packages, array $vars=null) {
		if (isset($vars['domain']))
			return $vars['domain'];
		return null;
	}
	
	/**
	 * Attempts to validate service info. This is the top-level error checking method. Sets Input errors on failure.
	 *
	 * @param stdClass $package A stdClass object representing the selected package
	 * @param array $vars An array of user supplied info to satisfy the request
	 * @return boolean True if the service validates, false otherwise. Sets Input errors when false.
	 */
	public function validateService($package, array $vars=null) {
        $rules = array();

        // Transfers (EPP Code)
	    if (isset($vars['transfer']) && ($vars['transfer'] === '2' || $vars['transfer'] == true)) {
            $rule = [
                'auth' => [
                    'empty' => array(
                        'rule' => array("isEmpty"),
                        'negate' => true,
                        'message' => Language::_("Namesilo.!error.epp.empty", true),
                        'post_format' => "trim"
                    )
                ],
            ];
            $rules = array_merge($rules,$rule);
        }

        // .us fields
        if(isset($vars['usnc']) || isset($vars['usap'])){
            $rule = [
{'fraction_non_alphanumeric': 0.11720959463705877, 'fraction_numerical': 0.0027233685974651723, 'mean_word_length': 2.867152693398137, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3249069', 'n_tokens_mistral': 2870, 'n_tokens_neox': 2610, 'n_words': 1037}