PHP
You should include a set of PHP classes to invoke methods of Integration API in your application. To do it, click the PHP classes link, copy the PHP code and paste it into the code of the application.
PHP classes
/**
* Extended SOAP client for simplified setup of credentials header
*
* @package Utils
* @copyright (c) 2004-2007, SWsoft
*/
class Utils_SoapClient extends SoapClient {
protected $_targetNamespace;
/**
* Constructor
*
* @param mixed $wsdl
* @param array $options
*/
public function __construct($wsdl, $options){
parent::__construct($wsdl, $options);
// detect target namespace
$xml = simplexml_load_file($wsdl);
$this->_targetNamespace = (string) $xml['targetNamespace'];
}
/**
* Set credentials header
*
* @param string $login
* @param string $password
*/
public function setCredentialsHeader($login, $password) {
$header = new SoapHeader($this->_targetNamespace,
'CredentialsSoapHeader',
new SoapVar(
array(
'Login' => $login,
'Password' => $password,
),
SOAP_ENC_OBJECT,
'CredentialsSoapHeader',
$this->_targetNamespace
)
);
$this->__setSoapHeaders(array($header));
}
}
Note: The classes should be declared before invoking Integration API methods.
For details on the set of classes, refer to the PHP Classes Details section.
To create a Plesk Sitebuilder site, the following steps should be taken:
1. Specify preferences common for all Plesk Sitebuilder web services.
The preferences are as follows:
- Web Services endpoint URL
- Login of a Plesk Sitebuilder user whose identity will be used to invoke methods of Integration API
- Password of the user
$serviceUrl = 'http://example.com/ServiceFacade/4.1/';
$serviceLogin = 'serviceLogin';
$servicePassword = 'servicePassword';
2. Create an instance of the SOAP client that invokes methods of web service SiteWebService.
$siteService = new Utils_SoapClient($serviceUrl.'/SiteWebService.asmx?WSDL', array());
$siteService->setCredentialsHeader($serviceLogin, $servicePassword);
3. Create an instance of standard PHP class stdClass and specify the site properties. The properties differ depending on a method that will be used for site creation. For details on the methods, refer to the Creating Site section.
A sample of the properties can look as follows:
$struct = new stdClass();
$struct->ownerId = 11;
$struct->siteType = 'Regular';
$struct->siteAlias = 'siteName';
$struct->hostId = 124;
$struct->publishingSettings = new stdClass();
$struct->publishingSettings->Scenario = 'Standard';
$struct->publishingSettings->Mode = 'Ftp';
$struct->publishingSettings->StandardLocation = new stdClass();
$struct->publishingSettings->StandardLocation->UserName = 'myUserName';
$struct->publishingSettings->StandardLocation->Password = 'publishFtpPassword';
$struct->publishingSettings->StandardLocation->WorkingDirectory = '/www/';
$struct->publishingSettings->StandardLocation->WebSiteUrl = 'http://example.com';
$struct->publishingSettings->StandardLocation->Address = 'ftp://example.com';
$struct->publishingSettings->StandardLocation->Veid = 0;
4. Invoke one of the methods used for creating sites. For details on the methods, refer to the Creating Site section. The following example illustrates the use of method CreateSite2.
$result = $siteService->CreateSite2(new SoapVar($struct, SOAP_ENC_OBJECT));
After the user account is created, you can retrieve preferences of the site. For instance, you can retrieve the ID of the site. The PHP code of the operation looks as follows:
$siteId = $result->CreateSite2Result->Id;
For full PHP code sample, click on the following link:
code sample.
<?php
/**
* Extended SOAP client for simplified setup of credentials header
*
* @package Utils
* @copyright (c) 2004-2007, SWsoft
*/
class Utils_SoapClient extends SoapClient {
protected $_targetNamespace;
/**
* Constructor
*
* @param mixed $wsdl
* @param array $options
*/
public function __construct($wsdl, $options){
parent::__construct($wsdl, $options);
// detect target namespace
$xml = simplexml_load_file($wsdl);
$this->_targetNamespace = (string) $xml['targetNamespace'];
}
/**
* Set credentials header
*
* @param string $login
* @param string $password
*/
public function setCredentialsHeader($login, $password) {
$header = new SoapHeader($this->_targetNamespace,
'CredentialsSoapHeader',
new SoapVar(
array(
'Login' => $login,
'Password' => $password,
),
SOAP_ENC_OBJECT,
'CredentialsSoapHeader',
$this->_targetNamespace
)
);
$this->__setSoapHeaders(array($header));
}
}$serviceUrl = 'http://example.com/ServiceFacade/4.1/';
$serviceLogin = 'serviceLogin';
$servicePassword = 'servicePassword';
$siteService = new Utils_SoapClient($serviceUrl.'/SiteWebService.asmx?WSDL', array());
$siteService->setCredentialsHeader($serviceLogin, $servicePassword);
$struct = new stdClass();
$struct->ownerId = 11;
$struct->siteType = 'Regular';
$struct->siteAlias = 'siteName';
$struct->hostId = 124;
$struct->publishingSettings = new stdClass();
$struct->publishingSettings->Scenario = 'Standard';
$struct->publishingSettings->Mode = 'Ftp';
$struct->publishingSettings->StandardLocation = new stdClass();
$struct->publishingSettings->StandardLocation->UserName = '/htdocs/';
$struct->publishingSettings->StandardLocation->Password = 'publishFtpPassword';
$struct->publishingSettings->StandardLocation->WorkingDirectory = '/www/';
$struct->publishingSettings->StandardLocation->WebSiteUrl = 'http://example.com';
$struct->publishingSettings->StandardLocation->Address = 'ftp://example.com';
$struct->publishingSettings->StandardLocation->Veid = 0;
$result = $siteService->CreateSite2(new SoapVar($struct, SOAP_ENC_OBJECT));
$siteId = $result->CreateSite2Result->Id;
?>