|
@@ -8,12 +8,11 @@ function checkDomainFormat($domain) {
|
|
|
|
|
|
function listFsDirs($username) {
|
|
|
$absoluteDirs = glob(CONF['ht']['ht_path'] . "/" . $username . "/*/", GLOB_ONLYDIR);
|
|
|
- $relativeDirs = false;
|
|
|
- foreach ($absoluteDirs as $i => $absoluteDir) {
|
|
|
+ $dirs = array();
|
|
|
+ foreach ($absoluteDirs as $absoluteDir)
|
|
|
if (preg_match("/^[a-z0-9-]{1,32}$/", basename($absoluteDir)))
|
|
|
- $relativeDirs[$i] = basename($absoluteDir); // The name of the site dir is the before last key
|
|
|
- }
|
|
|
- return $relativeDirs;
|
|
|
+ array_push($dirs, basename($absoluteDir));
|
|
|
+ return $dirs;
|
|
|
}
|
|
|
|
|
|
function addSite($username, $siteDir, $domain, $domainType, $protocol) {
|
|
@@ -40,7 +39,6 @@ function addSite($username, $siteDir, $domain, $domainType, $protocol) {
|
|
|
|
|
|
function listDbDirs($username, $domainType, $protocol) {
|
|
|
$db = new PDO('sqlite:' . DB_PATH);
|
|
|
- $usernameArray[0] = $username;
|
|
|
|
|
|
$op = $db->prepare('SELECT site_dir FROM sites WHERE username = :username AND domain_type = :domain_type AND protocol = :protocol');
|
|
|
$op->bindParam(':username', $username);
|
|
@@ -48,43 +46,20 @@ function listDbDirs($username, $domainType, $protocol) {
|
|
|
$op->bindParam(':protocol', $protocol);
|
|
|
$op->execute();
|
|
|
|
|
|
- $i = 0;
|
|
|
- $data = $op->fetch();
|
|
|
- if (isset($data['site_dir']))
|
|
|
- $siteDir = $data['site_dir'];
|
|
|
- else
|
|
|
- $siteDir = NULL;
|
|
|
-
|
|
|
- while ($siteDir != NULL) {
|
|
|
- $siteDirs[$i] = $siteDir;
|
|
|
- $i++;
|
|
|
- $data = $op->fetch();
|
|
|
- if (isset($data['site_dir']))
|
|
|
- $siteDir = $data['site_dir'];
|
|
|
- else
|
|
|
- $siteDir = NULL;
|
|
|
- }
|
|
|
- if (isset($siteDirs))
|
|
|
- return $siteDirs;
|
|
|
- else
|
|
|
- return false;
|
|
|
+ return array_column($op->fetchAll(PDO::FETCH_ASSOC), 'site_dir');
|
|
|
}
|
|
|
|
|
|
function dirsStatuses($username, $domainType, $protocol) {
|
|
|
- $dirs = false;
|
|
|
+ $dirs = array();
|
|
|
$fsDirs = listFsDirs($username);
|
|
|
$dbUsedDirs = listDbDirs($username, $domainType, $protocol);
|
|
|
- if ($fsDirs) {
|
|
|
- foreach ($fsDirs as $fsDir) {
|
|
|
- $dirs[$fsDir] = ($dbUsedDirs AND in_array($fsDir, $dbUsedDirs));
|
|
|
- }
|
|
|
- }
|
|
|
+ foreach ($fsDirs as $fsDir)
|
|
|
+ $dirs[$fsDir] = ($dbUsedDirs AND in_array($fsDir, $dbUsedDirs));
|
|
|
return $dirs;
|
|
|
}
|
|
|
|
|
|
function selectSites($username, $domainType, $protocol, $onlyLeAvailable) {
|
|
|
$db = new PDO('sqlite:' . DB_PATH);
|
|
|
- $usernameArray[0] = $username;
|
|
|
|
|
|
$query = "SELECT site_dir,domain FROM sites WHERE username = :username AND domain_type = :domain_type AND protocol = :protocol";
|
|
|
|