Thursday, February 21, 2013

google analytics api call using php

https://developers.google.com/analytics/devguides/reporting/
https://developers.google.com/analytics/solutions/articles/hello-analytics-api
https://code.google.com/apis/console
https://developers.google.com/analytics/devguides/platform/features/social-activities#advanced_config

<?php
function test2()
{
    $location = APP."libs".DS."google".DS;
    require_once $location.'mine/gapi.class.php';
    $ga = new gapi('name@domain.com','password');

    $ga->requestReportData(17472525,array('browser','browserVersion'),array('pageviews','visits'));

    foreach($ga->getResults() as $result)
    {
        echo '<strong>'.$result.'</strong><br />';
        echo 'Pageviews: ' . $result->getPageviews() . ' ';
        echo 'Visits: ' . $result->getVisits() . '<br />';
    }

    echo '<p>Total pageviews: ' . $ga->getPageviews() . ' total visits: ' . $ga->getVisits() . '</p>';
}
?>
Android Browser 534.13
Pageviews: 1 Visits: 1
Chrome 18.0.1025.166
Pageviews: 1 Visits: 1
Chrome 22.0.1229.79
Pageviews: 1 Visits: 1
Opera Mini 4.2.22537
Pageviews: 1 Visits: 1
Opera Mini 7.1.32249
Pageviews: 1 Visits: 1
Safari 532.4
Pageviews: 1 Visits: 1
Safari 533.3
Pageviews: 1 Visits: 1
Safari 534.8+
Pageviews: 1 Visits: 1
Firefox 17.0
Pageviews: 2 Visits: 2
Firefox 3.5
Pageviews: 2 Visits: 2
Mozilla Compatible Agent 5.0
Pageviews: 2 Visits: 2
Safari 6533.18.5
Pageviews: 2 Visits: 2
Chrome 21.0.1180.82
Pageviews: 4 Visits: 1
Chrome 24.2.0.0
Pageviews: 5 Visits: 1
Firefox 3.6.28
Pageviews: 5 Visits: 1
Chrome 17.0.963.66
Pageviews: 7 Visits: 1
Opera Mini 4.1.13572
Pageviews: 7 Visits: 2
Firefox 12.0
Pageviews: 8 Visits: 1
IE with Chrome Frame 8.0
Pageviews: 9 Visits: 1
Safari 536.25
Pageviews: 9 Visits: 1
Firefox 13.0
Pageviews: 12 Visits: 1
Chrome 26.0.1410.3
Pageviews: 13 Visits: 2
Safari (in-app) (not set)
Pageviews: 15 Visits: 6
Firefox 10.0.2
Pageviews: 16 Visits: 2
Internet Explorer 7.0
Pageviews: 16 Visits: 3
Android Browser 533.1
Pageviews: 20 Visits: 4
Chrome 17.0.963.81
Pageviews: 23 Visits: 1
Chrome 23.0.1271.97
Pageviews: 24 Visits: 3
Chrome 24.0.1312.52
Pageviews: 30 Visits: 5
Firefox 14.0.1
Pageviews: 31 Visits: 5
Total pageviews: 1674 total visits: 316

Sunday, February 17, 2013

validate domain name using php regex

<?php 
function isValidDomainName($name = null) {
    if(isValidString($name)) {
        if(preg_match("/^(?:[-A-Za-z0-9]+\.)+[A-Za-z]{2,6}$/", getValidString($name))) {
            return true;
        }
    }
    return false;
}

function isValidString($text = null)
{
    if ($text == null) {
        return false;
    }
    if (is_null($text)) {
        return false;
    }
    if (is_string($text)) {
        if (strlen(trim(strval($text)))  0) {
            return true;
        }
    }
    return false;
}
function getValidString($text = null)
{
    if (isValidString($text)) {
        return trim(strval($text));
    }
    return null;
} 
?>

all country list sql query

--
-- Table structure for table `countries`
--

CREATE TABLE `countries` (
  `ccode` varchar(2) NOT NULL default '',
  `country` varchar(200) NOT NULL default '',
  PRIMARY KEY  (`ccode`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

--
-- Dumping data for table `countries`
--

INSERT INTO `countries` VALUES ('AF', 'Afghanistan');
INSERT INTO `countries` VALUES ('AX', 'Åland Islands');
INSERT INTO `countries` VALUES ('AL', 'Albania');
INSERT INTO `countries` VALUES ('DZ', 'Algeria');
INSERT INTO `countries` VALUES ('AS', 'American Samoa');
INSERT INTO `countries` VALUES ('AD', 'Andorra');
INSERT INTO `countries` VALUES ('AO', 'Angola');
INSERT INTO `countries` VALUES ('AI', 'Anguilla');
INSERT INTO `countries` VALUES ('AQ', 'Antarctica');
INSERT INTO `countries` VALUES ('AG', 'Antigua and Barbuda');
INSERT INTO `countries` VALUES ('AR', 'Argentina');
INSERT INTO `countries` VALUES ('AM', 'Armenia');
INSERT INTO `countries` VALUES ('AW', 'Aruba');
INSERT INTO `countries` VALUES ('AU', 'Australia');
INSERT INTO `countries` VALUES ('AT', 'Austria');
INSERT INTO `countries` VALUES ('AZ', 'Azerbaijan');
INSERT INTO `countries` VALUES ('BS', 'Bahamas');
INSERT INTO `countries` VALUES ('BH', 'Bahrain');
INSERT INTO `countries` VALUES ('BD', 'Bangladesh');
INSERT INTO `countries` VALUES ('BB', 'Barbados');
INSERT INTO `countries` VALUES ('BY', 'Belarus');
INSERT INTO `countries` VALUES ('BE', 'Belgium');
INSERT INTO `countries` VALUES ('BZ', 'Belize');
INSERT INTO `countries` VALUES ('BJ', 'Benin');
INSERT INTO `countries` VALUES ('BM', 'Bermuda');
INSERT INTO `countries` VALUES ('BT', 'Bhutan');
INSERT INTO `countries` VALUES ('BO', 'Bolivia');
INSERT INTO `countries` VALUES ('BA', 'Bosnia and Herzegovina');
INSERT INTO `countries` VALUES ('BW', 'Botswana');
INSERT INTO `countries` VALUES ('BV', 'Bouvet Island');
INSERT INTO `countries` VALUES ('BR', 'Brazil');
INSERT INTO `countries` VALUES ('IO', 'British Indian Ocean Territory');
INSERT INTO `countries` VALUES ('BN', 'Brunei Darussalam');
INSERT INTO `countries` VALUES ('BG', 'Bulgaria');
INSERT INTO `countries` VALUES ('BF', 'Burkina Faso');
INSERT INTO `countries` VALUES ('BI', 'Burundi');
INSERT INTO `countries` VALUES ('KH', 'Cambodia');
INSERT INTO `countries` VALUES ('CM', 'Cameroon');
INSERT INTO `countries` VALUES ('CA', 'Canada');
INSERT INTO `countries` VALUES ('CV', 'Cape Verde');
INSERT INTO `countries` VALUES ('KY', 'Cayman Islands');
INSERT INTO `countries` VALUES ('CF', 'Central African Republic');
INSERT INTO `countries` VALUES ('TD', 'Chad');
INSERT INTO `countries` VALUES ('CL', 'Chile');
INSERT INTO `countries` VALUES ('CN', 'China');
INSERT INTO `countries` VALUES ('CX', 'Christmas Island');
INSERT INTO `countries` VALUES ('CC', 'Cocos (Keeling) Islands');
INSERT INTO `countries` VALUES ('CO', 'Colombia');
INSERT INTO `countries` VALUES ('KM', 'Comoros');
INSERT INTO `countries` VALUES ('CG', 'Congo');
INSERT INTO `countries` VALUES ('CD', 'Congo, The Democratic Republic of the');
INSERT INTO `countries` VALUES ('CK', 'Cook Islands');
INSERT INTO `countries` VALUES ('CR', 'Costa Rica');
INSERT INTO `countries` VALUES ('CI', 'Côte D\'Ivoire');
INSERT INTO `countries` VALUES ('HR', 'Croatia');
INSERT INTO `countries` VALUES ('CU', 'Cuba');
INSERT INTO `countries` VALUES ('CY', 'Cyprus');
INSERT INTO `countries` VALUES ('CZ', 'Czech Republic');
INSERT INTO `countries` VALUES ('DK', 'Denmark');
INSERT INTO `countries` VALUES ('DJ', 'Djibouti');
INSERT INTO `countries` VALUES ('DM', 'Dominica');
INSERT INTO `countries` VALUES ('DO', 'Dominican Republic');
INSERT INTO `countries` VALUES ('EC', 'Ecuador');
INSERT INTO `countries` VALUES ('EG', 'Egypt');
INSERT INTO `countries` VALUES ('SV', 'El Salvador');
INSERT INTO `countries` VALUES ('GQ', 'Equatorial Guinea');
INSERT INTO `countries` VALUES ('ER', 'Eritrea');
INSERT INTO `countries` VALUES ('EE', 'Estonia');
INSERT INTO `countries` VALUES ('ET', 'Ethiopia');
INSERT INTO `countries` VALUES ('FK', 'Falkland Islands (Malvinas)');
INSERT INTO `countries` VALUES ('FO', 'Faroe Islands');
INSERT INTO `countries` VALUES ('FJ', 'Fiji');
INSERT INTO `countries` VALUES ('FI', 'Finland');
INSERT INTO `countries` VALUES ('FR', 'France');
INSERT INTO `countries` VALUES ('GF', 'French Guiana');
INSERT INTO `countries` VALUES ('PF', 'French Polynesia');
INSERT INTO `countries` VALUES ('TF', 'French Southern Territories');
INSERT INTO `countries` VALUES ('GA', 'Gabon');
INSERT INTO `countries` VALUES ('GM', 'Gambia');
INSERT INTO `countries` VALUES ('GE', 'Georgia');
INSERT INTO `countries` VALUES ('DE', 'Germany');
INSERT INTO `countries` VALUES ('GH', 'Ghana');
INSERT INTO `countries` VALUES ('GI', 'Gibraltar');
INSERT INTO `countries` VALUES ('GR', 'Greece');
INSERT INTO `countries` VALUES ('GL', 'Greenland');
INSERT INTO `countries` VALUES ('GD', 'Grenada');
INSERT INTO `countries` VALUES ('GP', 'Guadeloupe');
INSERT INTO `countries` VALUES ('GU', 'Guam');
INSERT INTO `countries` VALUES ('GT', 'Guatemala');
INSERT INTO `countries` VALUES ('GG', 'Guernsey');
INSERT INTO `countries` VALUES ('GN', 'Guinea');
INSERT INTO `countries` VALUES ('GW', 'Guinea-Bissau');
INSERT INTO `countries` VALUES ('GY', 'Guyana');
INSERT INTO `countries` VALUES ('HT', 'Haiti');
INSERT INTO `countries` VALUES ('HM', 'Heard Island and McDonald Islands');
INSERT INTO `countries` VALUES ('VA', 'Holy See (Vatican City State)');
INSERT INTO `countries` VALUES ('HN', 'Honduras');
INSERT INTO `countries` VALUES ('HK', 'Hong Kong');
INSERT INTO `countries` VALUES ('HU', 'Hungary');
INSERT INTO `countries` VALUES ('IS', 'Iceland');
INSERT INTO `countries` VALUES ('IN', 'India');
INSERT INTO `countries` VALUES ('ID', 'Indonesia');
INSERT INTO `countries` VALUES ('IR', 'Iran, Islamic Republic of');
INSERT INTO `countries` VALUES ('IQ', 'Iraq');
INSERT INTO `countries` VALUES ('IE', 'Ireland');
INSERT INTO `countries` VALUES ('IM', 'Isle of Man');
INSERT INTO `countries` VALUES ('IL', 'Israel');
INSERT INTO `countries` VALUES ('IT', 'Italy');
INSERT INTO `countries` VALUES ('JM', 'Jamaica');
INSERT INTO `countries` VALUES ('JP', 'Japan');
INSERT INTO `countries` VALUES ('JE', 'Jersey');
INSERT INTO `countries` VALUES ('JO', 'Jordan');
INSERT INTO `countries` VALUES ('KZ', 'Kazakhstan');
INSERT INTO `countries` VALUES ('KE', 'Kenya');
INSERT INTO `countries` VALUES ('KI', 'Kiribati');
INSERT INTO `countries` VALUES ('KP', 'Korea, Democratic People\'s Republic of');
INSERT INTO `countries` VALUES ('KR', 'Korea, Republic of');
INSERT INTO `countries` VALUES ('KW', 'Kuwait');
INSERT INTO `countries` VALUES ('KG', 'Kyrgyzstan');
INSERT INTO `countries` VALUES ('LA', 'Lao People\'s Democratic Republic');
INSERT INTO `countries` VALUES ('LV', 'Latvia');
INSERT INTO `countries` VALUES ('LB', 'Lebanon');
INSERT INTO `countries` VALUES ('LS', 'Lesotho');
INSERT INTO `countries` VALUES ('LR', 'Liberia');
INSERT INTO `countries` VALUES ('LY', 'Libyan Arab Jamahiriya');
INSERT INTO `countries` VALUES ('LI', 'Liechtenstein');
INSERT INTO `countries` VALUES ('LT', 'Lithuania');
INSERT INTO `countries` VALUES ('LU', 'Luxembourg');
INSERT INTO `countries` VALUES ('MO', 'Macao');
INSERT INTO `countries` VALUES ('MK', 'Macedonia, The Former Yugoslav Republic of');
INSERT INTO `countries` VALUES ('MG', 'Madagascar');
INSERT INTO `countries` VALUES ('MW', 'Malawi');
INSERT INTO `countries` VALUES ('MY', 'Malaysia');
INSERT INTO `countries` VALUES ('MV', 'Maldives');
INSERT INTO `countries` VALUES ('ML', 'Mali');
INSERT INTO `countries` VALUES ('MT', 'Malta');
INSERT INTO `countries` VALUES ('MH', 'Marshall Islands');
INSERT INTO `countries` VALUES ('MQ', 'Martinique');
INSERT INTO `countries` VALUES ('MR', 'Mauritania');
INSERT INTO `countries` VALUES ('MU', 'Mauritius');
INSERT INTO `countries` VALUES ('YT', 'Mayotte');
INSERT INTO `countries` VALUES ('MX', 'Mexico');
INSERT INTO `countries` VALUES ('FM', 'Micronesia, Federated States of');
INSERT INTO `countries` VALUES ('MD', 'Moldova, Republic of');
INSERT INTO `countries` VALUES ('MC', 'Monaco');
INSERT INTO `countries` VALUES ('MN', 'Mongolia');
INSERT INTO `countries` VALUES ('ME', 'Montenegro');
INSERT INTO `countries` VALUES ('MS', 'Montserrat');
INSERT INTO `countries` VALUES ('MA', 'Morocco');
INSERT INTO `countries` VALUES ('MZ', 'Mozambique');
INSERT INTO `countries` VALUES ('MM', 'Myanmar');
INSERT INTO `countries` VALUES ('NA', 'Namibia');
INSERT INTO `countries` VALUES ('NR', 'Nauru');
INSERT INTO `countries` VALUES ('NP', 'Nepal');
INSERT INTO `countries` VALUES ('NL', 'Netherlands');
INSERT INTO `countries` VALUES ('AN', 'Netherlands Antilles');
INSERT INTO `countries` VALUES ('NC', 'New Caledonia');
INSERT INTO `countries` VALUES ('NZ', 'New Zealand');
INSERT INTO `countries` VALUES ('NI', 'Nicaragua');
INSERT INTO `countries` VALUES ('NE', 'Niger');
INSERT INTO `countries` VALUES ('NG', 'Nigeria');
INSERT INTO `countries` VALUES ('NU', 'Niue');
INSERT INTO `countries` VALUES ('NF', 'Norfolk Island');
INSERT INTO `countries` VALUES ('MP', 'Northern Mariana Islands');
INSERT INTO `countries` VALUES ('NO', 'Norway');
INSERT INTO `countries` VALUES ('OM', 'Oman');
INSERT INTO `countries` VALUES ('PK', 'Pakistan');
INSERT INTO `countries` VALUES ('PW', 'Palau');
INSERT INTO `countries` VALUES ('PS', 'Palestinian Territory, Occupied');
INSERT INTO `countries` VALUES ('PA', 'Panama');
INSERT INTO `countries` VALUES ('PG', 'Papua New Guinea');
INSERT INTO `countries` VALUES ('PY', 'Paraguay');
INSERT INTO `countries` VALUES ('PE', 'Peru');
INSERT INTO `countries` VALUES ('PH', 'Philippines');
INSERT INTO `countries` VALUES ('PN', 'Pitcairn');
INSERT INTO `countries` VALUES ('PL', 'Poland');
INSERT INTO `countries` VALUES ('PT', 'Portugal');
INSERT INTO `countries` VALUES ('PR', 'Puerto Rico');
INSERT INTO `countries` VALUES ('QA', 'Qatar');
INSERT INTO `countries` VALUES ('RE', 'Reunion');
INSERT INTO `countries` VALUES ('RO', 'Romania');
INSERT INTO `countries` VALUES ('RU', 'Russian Federation');
INSERT INTO `countries` VALUES ('RW', 'Rwanda');
INSERT INTO `countries` VALUES ('BL', 'Saint Barthélemy');
INSERT INTO `countries` VALUES ('SH', 'Saint Helena');
INSERT INTO `countries` VALUES ('KN', 'Saint Kitts and Nevis');
INSERT INTO `countries` VALUES ('LC', 'Saint Lucia');
INSERT INTO `countries` VALUES ('MF', 'Saint Martin');
INSERT INTO `countries` VALUES ('PM', 'Saint Pierre and Miquelon');
INSERT INTO `countries` VALUES ('VC', 'Saint Vincent and the Grenadines');
INSERT INTO `countries` VALUES ('WS', 'Samoa');
INSERT INTO `countries` VALUES ('SM', 'San Marino');
INSERT INTO `countries` VALUES ('ST', 'Sao Tome and Principe');
INSERT INTO `countries` VALUES ('SA', 'Saudi Arabia');
INSERT INTO `countries` VALUES ('SN', 'Senegal');
INSERT INTO `countries` VALUES ('RS', 'Serbia');
INSERT INTO `countries` VALUES ('SC', 'Seychelles');
INSERT INTO `countries` VALUES ('SL', 'Sierra Leone');
INSERT INTO `countries` VALUES ('SG', 'Singapore');
INSERT INTO `countries` VALUES ('SK', 'Slovakia');
INSERT INTO `countries` VALUES ('SI', 'Slovenia');
INSERT INTO `countries` VALUES ('SB', 'Solomon Islands');
INSERT INTO `countries` VALUES ('SO', 'Somalia');
INSERT INTO `countries` VALUES ('ZA', 'South Africa');
INSERT INTO `countries` VALUES ('GS', 'South Georgia and the South Sandwich Islands');
INSERT INTO `countries` VALUES ('ES', 'Spain');
INSERT INTO `countries` VALUES ('LK', 'Sri Lanka');
INSERT INTO `countries` VALUES ('SD', 'Sudan');
INSERT INTO `countries` VALUES ('SR', 'Suriname');
INSERT INTO `countries` VALUES ('SJ', 'Svalbard and Jan Mayen');
INSERT INTO `countries` VALUES ('SZ', 'Swaziland');
INSERT INTO `countries` VALUES ('SE', 'Sweden');
INSERT INTO `countries` VALUES ('CH', 'Switzerland');
INSERT INTO `countries` VALUES ('SY', 'Syrian Arab Republic');
INSERT INTO `countries` VALUES ('TW', 'Taiwan, Province Of China');
INSERT INTO `countries` VALUES ('TJ', 'Tajikistan');
INSERT INTO `countries` VALUES ('TZ', 'Tanzania, United Republic of');
INSERT INTO `countries` VALUES ('TH', 'Thailand');
INSERT INTO `countries` VALUES ('TL', 'Timor-Leste');
INSERT INTO `countries` VALUES ('TG', 'Togo');
INSERT INTO `countries` VALUES ('TK', 'Tokelau');
INSERT INTO `countries` VALUES ('TO', 'Tonga');
INSERT INTO `countries` VALUES ('TT', 'Trinidad and Tobago');
INSERT INTO `countries` VALUES ('TN', 'Tunisia');
INSERT INTO `countries` VALUES ('TR', 'Turkey');
INSERT INTO `countries` VALUES ('TM', 'Turkmenistan');
INSERT INTO `countries` VALUES ('TC', 'Turks and Caicos Islands');
INSERT INTO `countries` VALUES ('TV', 'Tuvalu');
INSERT INTO `countries` VALUES ('UG', 'Uganda');
INSERT INTO `countries` VALUES ('UA', 'Ukraine');
INSERT INTO `countries` VALUES ('AE', 'United Arab Emirates');
INSERT INTO `countries` VALUES ('GB', 'United Kingdom');
INSERT INTO `countries` VALUES ('US', 'United States');
INSERT INTO `countries` VALUES ('UM', 'United States Minor Outlying Islands');
INSERT INTO `countries` VALUES ('UY', 'Uruguay');
INSERT INTO `countries` VALUES ('UZ', 'Uzbekistan');
INSERT INTO `countries` VALUES ('VU', 'Vanuatu');
INSERT INTO `countries` VALUES ('VE', 'Venezuela');
INSERT INTO `countries` VALUES ('VN', 'Viet Nam');
INSERT INTO `countries` VALUES ('VG', 'Virgin Islands, British');
INSERT INTO `countries` VALUES ('VI', 'Virgin Islands, U.S.');
INSERT INTO `countries` VALUES ('WF', 'Wallis And Futuna');
INSERT INTO `countries` VALUES ('EH', 'Western Sahara');
INSERT INTO `countries` VALUES ('YE', 'Yemen');
INSERT INTO `countries` VALUES ('ZM', 'Zambia');
INSERT INTO `countries` VALUES ('ZW', 'Zimbabwe');

Friday, February 15, 2013

cpanel class for access cpanel data using php

Access hash authentication

You can write your script so that it includes an access hash, or "key," in the HTTP header that it sends to the server when it calls the API function. This method is only available to WHM users.
The access hash can be set up, and subsequently accessed, from the WHM Setup Remote Access Key feature. On your server, the hash resides in /root/.accesshash.

Online Code Beautify

Setup Remote Access Key

For WHM version 11.36
(Home >> Cluster/Remote Access >> Setup Remote Access Key)
This feature can be used to generate an access key. This access key can be used for automatic account creation scripts, external billing software, and allowing servers in your DNS cluster to exchange records.
To generate a new access key:
  1. Click Generate New Key.
  2. Copy and paste the new access key to the appropriate file on the remote server(s) that need to communicate with your web server. To use the remote access key to configure a DNS server cluster, follow our steps for configuring a cluster, pasting the key in on the Create Trust Relationship screen.

Download cpanel.class.php
 
<?php
class CPanelService
{
    var $disableStartup = true;
    var $server = '';
    var $url = '';
    var $user = '';
    var $pass = '';
    var $port = '';
    var $accessKey = '';
    var $ssl = false;
    var $whm = false;
    var $debug = false;
    var $xmlApi = true;
    var $error;

    function setXmlApi() {
        $this->xmlApi = true;
    }

    function setJsonApi() {
        $this->xmlApi = false;
    }

    function init($params = array())
    {
        if (isset($params['domain']) && isValidString($params['domain'])) {
            $this->domain = getValidString($params['domain']);
        } else {
            $this->error_log("Domain name required.");
            throw new Exception("Domain name required.");
        }

        if (isset($params['user']) && isValidString($params['user'])) {
            $this->user = getValidString($params['user']);
        } else {
            $this->error_log("User name required.");
            throw new Exception("User name required.");
        }

        if (isset($params['accessKey']) && isValidString($params['accessKey'])) {
            $this->accessKey = preg_replace("/(\n|\r|\s)/","",$params['accessKey']);
        } else if (isset($params['pass']) && isValidString($params['pass'])) {
            $this->pass = getValidString($params['pass']);
        } else {
            $this->error_log("Either password or access key required.");
            throw new Exception("Either password or access key required.");
        }

        if (isset($params['port']) && is_integer($params['port'])) $this->port = $params['port'];
        if (isset($params['ssl']) && is_bool($params['ssl'])) $this->ssl = $params['ssl'];
        if (isset($params['debug']) && is_bool($params['debug'])) $this->debug = $params['debug'];
        if (isset($params['whm']) && is_bool($params['whm'])) $this->whm = $params['whm'];

        if ($this->ssl) {
            $this->url = 'https';
        } else {
            $this->url = 'http';
        }
        if($this->whm) {
            $this->port = 2087;
        } else {
            $this->port = 2083;
        }
        $this->url .= '://' . $this->domain . ':' . $this->port."/";
        /*echo $this->url;*/
        return true;
    }

    private function xmlapi_query($function, $request = "")
    {
        if (!$function || !isValidString($function)) {
            $this->error_log('CPanel api query requires a function to be passed to it');
            return FALSE;
        }
        if(isValidString($request)) {
            $request = "?".$request;
        } else if(is_array($request) && count($request) > 0) {
            $request = "?".http_build_query($request);
        }
        if ($function) {
            $urlConnect = $this->url;
            if($this->xmlApi == true) {
                $urlConnect.="xml-api/";
            } else {
                $urlConnect.="json-api/";
            }

            $curl = curl_init (); // Initiate curl
            curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
            curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 0);

            curl_setopt ($curl, CURLOPT_URL, $urlConnect.$function.$request);
            if($this->debug) {
                echo "<BR>".$urlConnect.$function.$request."<BR>";
            }

            curl_setopt ($curl, CURLOPT_HEADER, 0);
            curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);

            $customHeader[0] = "Authorization: WHM ".$this->user.':'.$this->accessKey;
            curl_setopt($curl, CURLOPT_HTTPHEADER, $customHeader);


            /*execute the query*/
            $result = curl_exec($curl);
            if ($result == false) {
                $this->error_log("curl_exec threw error \"" . curl_error($curl) . "\" for ".$this->url);
            }
            if (stristr($result, '<body>') == TRUE) {
                /*echo $result; die();*/
                if (stristr($result, 'Invalid security token') == TRUE) {
                    curl_close($curl);
                    $this->error = 'Invalid security token';
                    return FALSE;
                }
                if (stristr($result, 'Login Attempt Failed') == TRUE) {
                    curl_close($curl);
                    $this->error = 'Login Attempt Failed';
                    return FALSE;
                }
                if (stristr($result, 'action="/login/"') == TRUE) {
                    curl_close($curl);
                    $this->error = 'Authentication Error';
                    return FALSE;
                }
                if (stristr($result, '404 Not Found') == TRUE) {
                    curl_close($curl);
                    $this->error = 'cPanel API 404 Error';
                    return FALSE;
                }
                curl_close($curl);
                $this->error = 'Generic Error'.$result;
                return FALSE;
            }
            if ($result == FALSE) {
                $this->error = 'curl_error threw error "' . curl_error($curl) . '"';
                curl_close($curl);
                return FALSE;
            }
            curl_close($curl);
            if($this->xmlApi) {
                $obj = new XmlParser();
                $resultObj = $obj->parseString($result);
                return $resultObj;
            } else {
                return json_decode($result);
            }
        }
        return false;
    }

/**
     * Call an API2 Function
     * This function allows you to call an API2 function, this is the modern API for cPanel and should be used in preference over
     * API1 when possible
     *
     * @param string $user The username of the account to perform API2 actions on
     * @param string $module The module of the API2 call to use
     * @param string $function The function of the API2 call
     * @param array $args An associative array containing the arguments for the API2 call
     * @return mixed
     * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/CallingAPIFunctions XML API Call documentation
     * @link http://docs.cpanel.net/twiki/bin/view/DeveloperResources/ApiRef/WebHome API1 & API2 Call documentation
     * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/ApiTwo Legacy API2 Documentation
     * @link http://docs.cpanel.net/twiki/bin/view/DeveloperResources/ApiBasics/CallingApiTwo API2 Documentation
     */
    public function api2_query($user, $module, $function, $args = array())
    {
        if (!isset($user) || !isset($module) || !isset($function) ) {
            error_log("api2_query requires that a username, module and function are passed to it");

            return false;
        }
        if (!is_array($args)) {
            error_log("api2_query requires that an array is passed to it as the 4th parameter");

            return false;
        }

        $cpuser = 'cpanel_xmlapi_user';
        $module_type = 'cpanel_xmlapi_module';
        $func_type = 'cpanel_xmlapi_func';
        $api_type = 'cpanel_xmlapi_apiversion';

        if ( !$this->xmlApi ) {
            $cpuser = 'cpanel_jsonapi_user';
            $module_type = 'cpanel_jsonapi_module';
            $func_type = 'cpanel_jsonapi_func';
            $api_type = 'cpanel_jsonapi_apiversion';
        }

        $args[$cpuser] = $user;
        $args[$module_type] = $module;
        $args[$func_type] = $function;
        $args[$api_type] = '2';

        return $this->xmlapi_query('cpanel', $args);
    }

    private function error_log($error)
    {
        $this->error = $error;
        return FALSE;
    }

    public function getError()
    {
        return $this->error;
    }

    public function getApiList()
    {
        return $this->xmlapi_query('applist');
    }

    public function getVersion()
    {
        return $this->xmlapi_query('version');
    }

    ####
    # Account functions
    ####

    // This API function allows you to create new cPanel accounts.
    // $acctconf = array('username' => string, 'password' => string, 'domain' => string)
    // Optional variables (f.e. plan, contactemail, cpmod, language, etc.) can be found at:
    // Info: http://twiki.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/CreateAccount
    public function createAccount($userName = "", $password = "", $domain = "")
    {
        if (!isValidString($userName) || !isValidString($password)
        || !isValidString($domain)) {
            error_log("createAccount requires that username, password & domain name");
            return FALSE;
        }
        return $this->xmlapi_query('createacct', array(
            "username" => "".$userName,
            "password" => "".$password,
            "domain" => "".$domain
        ));
    }

    // Using this API function, you can change a cPanel account's password.
    // $username = string, $pass = string
    public function changePassword($username, $pass)
    {
        if (!isset($username) || !isset($pass)) {
            error_log("Change password requires that an username and password are passed to it");
            return FALSE;
        }
        return $this->xmlapi_query('passwd', array('user' => $username, 'pass' => $pass));
    }
    public function changeFtpPassword($username, $password)
    {
        if (!isset($username) || !isset($pass)) {
            error_log("Change password requires that an username and password are passed to it");
            return FALSE;
        }
        return $this->api2_query($username, "Ftp", "passwd", array('user' => $username, 'pass' => $pass));
    }

    // This API function allows you to change bandwidth limits for cPanel accounts.
    // $username = string, $bwlimit = integer (in Megabytes)
    public function setBandWidthLimit($username, $bwlimit)
    {
        if (!isset($username) || !isset($bwlimit)) {
            error_log("Limit Bandwidth requires that an username and bwlimit are passed to it");
            return FALSE;
        }
        return $this->xmlapi_query('limitbw', array('user' => $username, 'bwlimit' => $bwlimit));
    }

    // This API function will generate a list of accounts associated with a server.
    // $searchtype = string (Allowed values: domain, owner, user, ip, package)
    // $search = string (regular expression)
    // Info: http://twiki.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/ListAccounts
    public function getAccountList($searchtype = null, $search = null)
    {
        if ($search) {
            return $this->xmlapi_query('listaccts', array('searchtype' => $searchtype, 'search' => $search));
        }
        return $this->xmlapi_query('listaccts');
    }

    // Using this API function, you are able to change specific attributes of cPanel accounts, such as the theme or domain.
    // $opts = array('user' => string). Optional variables can be found at:
    // Info: http://twiki.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/ModifyAccount
    private function modifyAcct($opts)
    {
        if (!isset($opts['user'])) {
            error_log("modifyacct requires that user is defined in the array passed to it");
            return FALSE;
        }
        return $this->xmlapi_query('modifyacct', $opts);
    }

    // This API function allows you to edit a user's disk space quota.
    // $username = string, $quota = integer (in Megabytes)
    private function editquota($username, $quota)
    {
        if (!isset($username) || !isset($quota)) {
            error_log("editquota requires that an username and quota are passed to it");
            return FALSE;
        }
        return $this->xmlapi_query('editquota', array('user' => $username, 'quota' => $quota));
    }

    // This API function will generate a list of an account's attributes, such as it's IP address and partition.
    // $username = string
    public function getAccountSummary($username)
    {
        if (!isset($username)) {
            error_log("accountsummary requires that an username is passed to it");
            return FALSE;
        }
        return $this->xmlapi_query('accountsummary', array('user' => $username));
    }

    // Using this API function, you can prevent a user from accessing his or her cPanel account.
    // $username = string
    // Optional: $reason = string
    public function suspendAccount($username, $reason = null)
    {
        if (!isset($username)) {
            error_log("suspendacct requires that an username is passed to it");
            return FALSE;
        }
        if ($reason) {
            return $this->xmlapi_query('suspendacct', array('user' => $username, 'reason' => $reason));
        }
        return $this->xmlapi_query('suspendacct', array('user' => $username));
    }

    // This function allows you to view a list of suspended accounts on your server.
    public function getSuspendAccountList()
    {
        return $this->xmlapi_query('listsuspended');
    }

    // This API function allows you permanently remove an account from a server.
    // $username = string
    // Optional: $keepdns = boolean (1 or 2). 1 = yes, 2 = no (this is the default value).
    public function removeAccount($username, $keepdns = null)
    {
        if (!isset($username)) {
            error_log("removeacct requires that a username is passed to it");
            return FALSE;
        }
        if ($keepdns) {
            return $this->xmlapi_query('removeacct', array('user' => $username, 'keepdns' => $keepdns));
        }
        return $this->xmlapi_query('removeacct', array('user' => $username));
    }

    // Using this API function, you can allow a user to access his or her cPanel account after it has been suspended.
    // $username = string
    public function unSuspendAccount($username)
    {
        if (!isset($username)) {
            error_log("unsuspendacct requires that a username is passed to it");
            return FALSE;
        }
        return $this->xmlapi_query('unsuspendacct', array('user' => $username));
    }

    // This API function allows you to change the hosting plan associated with a cPanel account.
    // $username = string, $pkg = string
    public function changePackage($username, $pkg)
    {
        if (!isset($username) || !isset($pkg)) {
            error_log("changepackage requires that username and pkg are passed to it");
            return FALSE;
        }
        return $this->xmlapi_query('changepackage', array('user' => $username, 'pkg' => $pkg));
    }

    // Using this API function, you can find out what privileges you have within WHM.
    public function getPrivilege()
    {
        return $this->xmlapi_query('myprivs');
    }

    // Function available in WHM 11.25 and later: domainuserdata
    // This function displays information about a given domain,
    // including addon and subdomains, whether CGI aliasing is enabled, log locations, and other details.

    // Function available in WHM 11.25 and later: setsiteip
    // This function allows you to change the IP address associated with a website, or a user's account, hosted on your server.

    ####
    # DNS Functions
    ####

    // This API function lets you create a DNS zone.
    // $domain = string, $ip = string
    public function addDnsRecord($domain, $ip)
    {
        if (!isset($domain) || !isset($ip)) {
            error_log("adddns require that domain, ip are passed to it");
            return FALSE;
        }
        return $this->xmlapi_query('adddns', array('domain' => $domain, 'ip' => $ip));
    }

    // Function available in WHM 11.25 and later: addzonerecord
    // This API function allows you to add a zone record.

    // Function available in WHM 11.25 and later: editzonerecord
    // This function allows you to edit an existing zone record.

    // Function available in WHM 11.25 and later: getzonerecord
    // This function allows you to view DNS zone records associated with a given domain.

    // This API function lets you delete a DNS zone.
    // $domain = string
    public function killDnsRecord($domain)
    {
        if (!isset($domain)) {
            error_log("killdns requires that domain is passed to it");
            return FALSE;
        }
        return $this->xmlapi_query('killdns', array('domain' => $domain));
    }

    // This API function lists all domains and DNS zones on your server.
    public function getZoneList()
    {
        return $this->xmlapi_query('listzones');
    }

    // This API function displays the DNS zone configuration for a specific domain.
    // $domain = string
    public function dumpZone($domain)
    {
        if (!isset($domain)) {
            error_log("dumpzone requires that a domain is passed to it");
            return FALSE;
        }
        return $this->xmlapi_query('dumpzone', array('domain' => $domain));
    }

    // This API function retrives the IP address of a registered nameserver.
    // $nameserver = string
    public function LookUpNsIp($nameserver)
    {
        if (!isset($nameserver)) {
            error_log("lookupnsip requres that a nameserver is passed to it");
            return FALSE;
        }
        return $this->xmlapi_query('lookupnsip', array('nameserver' => $nameserver));
    }

    // Function available in WHM 11.25 and later: removezonerecord
    // This function allows you to remove a zone record from the server.

    // Function available in WHM 11.25 and later: resetzone
    // This API function will reset a DNS zone to its default values.

    ####
    # Package Functions
    ####

    // This API function adds a hosting package to your server.
    // $pkg = array('name' => string). Optional variables can be found at:
    // Info: http://twiki.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/AddPackage
    public function addPackage($pkg)
    {
        if (!isset($pkg['name'])) {
            error_log("addpkg requires that name is defined in the array passed to it");
            return FALSE;
        }
        return $this->xmlapi_query('addpkg', $pkg);
    }

    // This API function deletes a hosting package from your server.
    // $pkgname = string
    public function killPackage($pkgname)
    {
        if (!isset($pkgname)) {
            error_log("killpkg requires that the package name is passed to it");
            return FALSE;
        }
        return $this->xmlapi_query('killpkg', array('pkg' => $pkgname));
    }

    // This function lets you edit aspects of a hosting package.
    // $pkg = array('name' => string). Optional variables can be found at:
    // Info: http://twiki.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/EditPackage
    public function editPackage($pkg)
    {
        if (!isset($pkg['name'])) {
            error_log("editpkg requires that name is defined in the array passed to it");
            return FALSE;
        }
        return $this->xmlapi_query('editpkg', $pkg);
    }

    // This API function lets you view all hosting packages available to the user.
    public function getPackageList()
    {
        return $this->xmlapi_query('listpkgs');
    }

    ####
    # Reseller functions
    ####

    // This function allows you to confer reseller status to a user's account.
    // $username = string
    // Optional: $makeowner = boolean (0 or 1). Default is 1 (yes).
    // Info: http://twiki.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/AddResellerPrivileges
    public function setUpReseller($username, $makeowner = '1')
    {
        if (!isset($username)) {
            error_log("setupreseller requires that username is passed to it");
            return FALSE;
        }
        return $this->xmlapi_query('setupreseller', array('user' => $username, 'makeowner' => $makeowner));
    }

    // This function allows you to create a new ACL list to use when setting up reseller accounts.
    // $acl = array('acllist' => string). Optional variables can be found at:
    // Info: http://twiki.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/CreateResellerACLList
    public function saveAclList($acl)
    {
        if (!isset($acl['acllist'])) {
            error_log("saveacllist requires that acllist is defined in the array passed to it");
            return FALSE;
        }
        return $this->xmlapi_query('saveacllist', $acl);
    }

    // This function lists the saved reseller ACL lists on the server.
    function listacls()
    {
        return $this->xmlapi_query('listacls');
    }

    // This function lists all resellers on the server.
    function listresellers()
    {
        return $this->xmlapi_query('listresellers');
    }

    // This function shows statistics for a specific reseller's accounts.
    // $username = string
    function resellerstats($username)
    {
        if (!isset($username)) {
            error_log("resellerstats requires that a username is passed to it");
            return FALSE;
        }
        return $this->xmlapi_query('resellerstats', array('reseller' => $username));
    }

    // This function removes reseller status from a user's account.
    // $username = string
    function unsetupreseller($username)
    {
        if (!isset($username)) {
            error_log("unsetupreseller requires that a username is passed to it");
            return FALSE;
        }
        return $this->xmlapi_query('unsetupreseller', array('user' => $username));
    }

    // This function specifies the ACL for a reseller, or modifies specific ACL features for a reseller.
    // $acl = array('reseller' => string). Optional variables can be found at:
    // Info: http://twiki.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/SetResellersACLList
    function setacls($acl)
    {
        if (!isset($acl['reseller'])) {
            error_log("setacls requires that reseller is defined in the array passed to it");
            return FALSE;
        }
        return $this->xmlapi_query('setacls', $acl);
    }

    // This function allows you to terminate a reseller's account.
    // $username = string
    // WARNING!: This will irrevocably remove all the accounts owned by that reseller!
    function terminatereseller($username)
    {
        if (!isset($reseller)) {
            error_log("terminatereseller requires that username is passed to it");
            return FALSE;
        }
        $verify = 'I%20understand%20this%20will%20irrevocably%20remove%20all%20the%20accounts%20owned%20by%20the%20reseller%20' . $username;
        return $this->xmlapi_query('terminatereseller', array('reseller' => $username, 'terminatereseller' => '1', 'verify' => $verify));
    }

    // Function available in WHM 11.25 and later: setresellerips
    // This function lets you add IP addresses to a reseller's account.

    // Function available in WHM 11.25 and later: setresellerlimits
    // This function lets you set limits on the amount of bandwidth and disk space a reseller can use.

    // Function available in WHM 11.25 and later: setresellermainip
    // This function lets you assign a main, shared IP address to a reseller's account.

    // Function available in WHM 11.25 and later: setresellerpackagelimit
    // This function allows you to control which packages resellers are able to use.
    // It also lets you define the number of times a package can be used by a reseller.

    // Function available in WHM 11.25 and later: suspendreseller
    // This function lets you suspend a reseller, thereby preventing the reseller from accessing his or her account.

    // Function available in WHM 11.25 and later: unsuspendreseller
    // This function lets you unsuspend a reseller, thereby allowing the reseller to access his or her account.

    // Function available in WHM 11.25 and later: acctcounts
    // This function lists the number of accounts owned by each reseller on the server.

    // Function available in WHM 11.25 and later: setresellernameservers
    // This function allows you to define a reseller's nameservers.

    ####
    # Server information
    ####

    // This function displays the server's hostname.
    function gethostname()
    {
        return $this->xmlapi_query('gethostname');
    }

    // This function displays the version of cPanel/WHM running on the server.
    function version()
    {
        return $this->xmlapi_query('version');
    }

    // This function displays your server's load average.
    function loadavg()
    {
        return $this->xmlapi_query('loadavg');
    }

    // This function displays a list of the languages available on your server.
    function getlanglist()
    {
        return $this->xmlapi_query('getlanglist');
    }

    ####
    # Server administration
    ####

    // This function allows you to restart your server.
    // Optional: $force = boolean (0 or 1)
    // 1  Initiates the forceful reboot
    // 0  Initiates a graceful reboot (default).
    // Remember: A forceful reboot may result in data loss if processes are still running when the server restarts.
    function reboot($force = null)
    {
        if ($force) {
            return $this->xmlapi_query('reboot', array('force' => $force));
        }
        return $this->xmlapi_query('reboot');
    }

    // This function allows you to add an IP address to your server.
    // $ip = string, $netmask = string
    // Info: http://twiki.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/AddIPAddress
    function addip($ip, $netmask)
    {
        if (!isset($ip) || !isset($netmask)) {
            error_log("addip requires that an IP address and Netmask are passed to it");
            return FALSE;
        }
        return $this->xmlapi_query('addip', array('ip' => $ip, 'netmask' => $netmask));
    }

    // This function allows you to delete an IP address from your server.
    // $opts = array('ip' => string). Optional variables can be found at:
    // Info: http://twiki.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/DeleteIPAddress
    function delip($opts)
    {
        if (!isset($opts['ip'])) {
            error_log("delip requires that an IP is defined in the array passed to it");
            return FALSE;
        }
        return $this->xmlapi_query('delip', $opts);
    }

    // This function allows you to list IP addresses associated with your server.
    function listips()
    {
        return $this->xmlapi_query('listips');
    }

    // This function allows you to set the hostname for your server.
    // Note: This name must be different from your domain name.
    // $hostname = string
    function sethostname($hostname)
    {
        if (!isset($hostname)) {
            error_log("sethostname requires that hostname is passed to it");
            return FALSE;
        }
        return $this->xmlapi_query('sethostname', array('hostname' => $hostname));
    }

    // This function allows you to set the resolvers your server will use.
    // $resv = array('nameserver1' => string [, 'nameserver2' => string, 'nameserver3' => string])
    // nameserver1 is required, the other two are optional
    function setresolvers($resv)
    {
        if (!isset($resv['nameserver1'])) {
            error_log("setresolvers requires that nameserver1 is defined in the array passed to it");
            return FALSE;
        }
        return $this->xmlapi_query('setresolvers', $resv);
    }

    // This function will list bandwidth usage per account.
    // $opts = array(). Optional variables can be found at:
    // Info: http://twiki.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/ShowBw
    function showbw($opts = null)
    {
        if (is_array($opts)) {
            return $this->xmlapi_query('showbw', $opts);
        }
        return $this->xmlapi_query('showbw');
    }

    // Non-volatile variables are used to save data on your server.
    // This function allows you to set a non-volatile variable's value.
    // $key = string, $value = string
    // Info: http://twiki.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/NvSet
    function nvset($key, $value)
    {
        if (!isset($key) || !isset($value)) {
            error_log("nvset requires that key and value are passed to it");
            return FALSE;
        }
        return $this->xmlapi_query('nvset', array('key' => $key, 'value' => $value));
    }

    // This function allows you to retrieve and view a non-volatile variable's value.
    // $key = string
    function nvget($key)
    {
        if (!isset($key)) {
            error_log("nvget requires that key is passed to it");
            return FALSE;
        }
        return $this->xmlapi_query('nvget', array('key' => $key));
    }

    ####
    # Service functions
    ####

    // This function lets you restart a service, or daemon, on your server.
    // $service = string
    // Acceptable values: named, interchange, ftpd, httpd, imap, cppop, exim, mysql, postgresql, sshd or tomcat
    function restartsrv($service)
    {
        if (!isset($service)) {
            error_log("restartsrv requires that service is passed to it");
            return FALSE;
        }
        return $this->xmlapi_query('restartservice', array('service' => $service));
    }

    // This function tells you which services (daemons) are enabled, installed, and monitored on your server.
    function servicestatus()
    {
        return $this->xmlapi_query('servicestatus');
    }

    // Function available in WHM 11.25 and later: configureservice
    // This function allows you to enable or disable a service,
    // and enable or disable monitoring of that service, as in the WHM Service Manager.

    ####
    # SSL functions
    ####

    // This function displays an SSL certificate, CA bundle, and private key for a specified domain,
    // or it can display a CA bundle and private key for a specified SSL certificate.
    // $args = array(['domain' => string] or ['crtdata' => string]) one is required, not both!
    // Info: http://twiki.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/FetchSSL
    function fetchsslinfo($args)
    {
        if (!isset($args['domain']) && !isset($args['crtdata'])) {
            error_log("fetchsslinfo requires domain OR crtdata is passed to it");
        }
        if (isset($args['crtdata'])) {
            // crtdata must be URL-encoded!
            $args['crtdata'] = urlencode($args['crtdata']);
        }
        return $this->xmlapi_query('fetchsslinfo', $args);
    }

    // This function generates an SSL certificate.
    // $args = array('xemail' => string, 'host' => string, 'country' => string, 'state' => string, 'city' => string, 'co' => string, 'cod' => string, 'email' => string, 'pass' => string)
    // Info: http://twiki.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/GenerateSSL
    function generatessl($args)
    {
        if (!isset($args['xemail']) || !isset($args['host']) || !isset($args['country']) || !isset($args['state']) || !isset($args['city']) || !isset($args['co']) || !isset($args['cod']) || !isset($args['email']) || !isset($args['pass'])) {
            error_log("generatessl requires that xemail, host, country, state, city, co, cod, email and pass are defined in the array passed to it");
            return FALSE;
        }
        return $this->xmlapi_query('generatessl', $args);
    }

    // This function lets you install an SSL certificate onto the server.
    // $args = array('user' => string, 'domain' => string, 'cert' => string, 'key' => string, 'cab' => string, 'ip' => string)
    // Info: http://twiki.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/InstallSSL
    function installssl($args)
    {
        if (!isset($args['user']) || !isset($args['domain']) || !isset($args['cert']) || !isset($args['key']) || !isset($args['cab']) || !isset($args['ip'])) {
            error_log("installssl requires that user, domain, cert, key, cab and ip are defined in the array passed to it");
            return FALSE;
        }
        return $this->xmlapi_query('installssl', $args);
    }

    // This function lists all domains on the server which have SSL certificates installed.
    function listcrts()
    {
        return $this->xmlapi_query('listcrts');
    }

    ####
    # cPanel API1 functions
    # Note: A cPanel account username is required
    # Some cPanel features must be enabled to be able to use some function (f.e. park, unpark)
    ####

    // This API1 function adds a emailaccount for a specific user.
    // $args = array('email_username', 'email_password', 'email_domain')
    function addpop($username, $args)
    {
        if (!isset($username) || !isset($args)) {
            error_log("addpop requires that a user and args are passed to it");
            return FALSE;
        }
        if (is_array($args) && (sizeof($args) < 3)) {
            error_log("addpop requires that args at least contains an email_username, email_password and email_domain");
            return FALSE;
        }
        return $this->api1_query($username, 'Email', 'addpop', $args);
    }

    ####
    # cPanel API2 functions
    # Note: A cPanel account username is required
    # Some cPanel features must be enabled to be able to use some function
    ####

    // This API2 function allows you to view the diskusage of a emailaccount.
    // $args = array('domain' => $email_domain, 'login' => $email_username)
    function getdiskusage($username, $args)
    {
        if (!isset($username) || !isset($args)) {
            error_log("getdiskusage requires that a username and args are passed to it");
            return FALSE;
        }
        if (is_array($args) && (!isset($args['domain']) || !isset($args['login']))) {
            error_log("getdiskusage requires that args at least contains an email_domain and email_username");
            return FALSE;
        }
        return $this->api2_query($username, 'Email', 'getdiskusage', $args);
    }

    // This API2 function allows you to list ftp-users associated with a cPanel account.
    function listftpwithdisk($username)
    {
        if (!isset($username)) {
            error_log("listftpwithdisk requires that user is passed to it");
            return FALSE;
        }
        return $this->api2_query($username, 'Ftp', 'listftpwithdisk');
    }

    // This API function displays a list of all parked domains for a specific user.
    function listparkeddomains($username)
    {
        if (!isset($username)) {
            error_log("listparkeddomains requires that a user is passed to it");
            return FALSE;
        }
        return $this->api2_query($username, 'Park', 'listparkeddomains');
    }
}

class XmlParser {
    public function parseString($xml) {
        $xmlObj = simplexml_load_string($xml);
        $xmlObj = $this->objectsIntoArray($xmlObj);
        return $xmlObj;
    }

    private function objectsIntoArray($arrObjData, $arrSkipIndices = array())
    {
        $arrData = array();

        // if input is object, convert into array
        if (is_object($arrObjData)) {
            $arrObjData = get_object_vars($arrObjData);
        }

        if (is_array($arrObjData)) {
            foreach ($arrObjData as $index => $value) {
                if (is_object($value) || is_array($value)) {
                    $value = $this->objectsIntoArray($value, $arrSkipIndices); // recursive call
                }
                if (in_array($index, $arrSkipIndices)) {
                    continue;
                }
                $arrData[$index] = $value;
            }
        }
        return $arrData;
    }
}

?>

<?php 
    $cPanel = new CPanelService();
    $cPanel->init(
        array(
            'domain' =>'server.name.com',
            'user' => 'root',
            'pass' => 'fakePassword',
            'accessKey' => "1b148d74db356509994daa73d5f306a4a",
            'port' => 2083,
            'ssl' => true,
            "debug" => true,
            "whm" => true
        )
    );
    if($cPanel == false) {
        echo $cPanel->getError();
        die();
    }
    $cPanel->setJsonApi();
    $list = $cPanel->getApiList();
    if($list == false) {
        echo $cPanel->getError();
        die();
    } else {
        print_r($list);
    }
?>