Location: PHPKode > scripts > HostBuilder > hostbuilder/functions.php
<?php
/*
	HostBuilder
	Free Edition
	(C) 2007-2008 Data Components Software Development

	Functions and procedures
*/

function showlogin($commname) {
  $t['community'] = $commname;
	return parse_tpl("manager.login", $t);
}

function authenticate ($username, $password) {
	$passwd = getacctpasswd($username);
	if ($passwd == $password) {
		return true;
	} else {
		return false;
	}
}

function getacctpasswd ($username) {
	return getaccountinfo($username, 1);
}

function getconfigpath () {
	$cvarline = file(getcwd()."/config.inc");
	$cvalues = split("::", $cvarline[0]);
	fclose ($chnd);
	return $cvalues[5];
}

function showfiles ($member) {
  $d1 = getmemberdir($member);
	$d = opendir($d1);
	while ($f = readdir($d)) {
	  if (!is_dir($d1."/".$f) && $f != "." && $f != "..") {
	    $f1[] = $f;
	  }
	}
	closedir($d);
	sort($f1);
	foreach ($f1 as $f) {
    $b['link'] = getaccountinfo($member, 9)."/".$f;
    $b['file'] = $f;
    $b['size'] = getfilesize($d1."/".$file)." KB";
    $b['date'] = date("F d Y", filemtime($d1."/".$f));
    $a['files'] .= parse_tpl("manager.fileitem", $b);
	}
  return parse_tpl("manager.files", $a);
}

function getmemberdir ($member) {
	$f = file(getcwd()."/accounts.db");
	foreach ($f as $l) {
	  $v = split("::", $l);
	  if ($v[0] == $member) {
	    return $v[5];
	  }
	}
}

function getfilesize ($file) {
	return round((filesize($file)/1024), 2);
}

function showpanel () {
	$t['used'] = round((getmemberusedspace($_COOKIE['th_username'])/1024), 2);
  $t['total'] = round((getmemberspace($_COOKIE['th_username'])/1024), 2);
  $t['free'] = round((getmemberspace($_COOKIE['th_username'])-getmemberusedspace($_COOKIE['th_username']))/1024, 2)." KB";
  return parse_tpl("manager.panel", $t);
}

function login ($username, $password) {
	setcookie("th_username", $username);
	setcookie("th_password", $password);
	$_COOKIE['th_username'] = $username;
	$_COOKIE['th_password'] = $password;
	changedata ($username, 6, time());
}

function getmemberspace($username) {
	$f = file(getcwd()."/accounts.db");
	foreach ($f as $l) {
		$v = split("::", $l);
		if ($username == $v[0]) {
			return $v[2]*1024;
		}
	}
}

function getmemberusedspace($username) {
    return dirsize(getmemberdir($username));
}

function dirsize($dir) {
  $h = opendir($dir);
  $size = 0;
  while ($d = readdir($h)) {
    if (is_dir($dir."/".$d) && $d != "." && $d != "..") {
      $size += dirsize($dir."/".$d);
    } elseif (is_file($dir."/".$d) && $d != "." && $d != "..") {
      $size += filesize($dir."/".$d);
    }
  }
  return $size;
}

function getconfig($id) {
	$f = file(getcwd()."/config.inc");
	$cv = split("::", $f[0]);
	return $cv[$id];
}

function getaccountinfo($member, $id) {
	$f = file(getcwd()."/accounts.db");
	foreach ($f as $line) {
	  $line = trim($line);
		$values = split("::", $line);
		if ($member == $values[0]) {
			return $values[$id];
			exit;
		}
		$cnt++;
	}
	return false;
}

function showrenamepanel ($filelist) {
	$f = split(",", $filelist);
  $t['total'] = count($f);
  $id = 1;
  foreach ($f as $fl) {
    $a['id'] = $id;
    $id++;
    $a['file'] = $fl;
   	$t['files'] .= parse_tpl("manager.renameitem", $a);
  }
  return parse_tpl("manager.rename", $t);
}

function showmessage ($title, $outmsg) {
  $t['title'] = $title;
  $t['message'] = $outmsg;
	return parse_tpl("message2", $t);
}

function showerror ($outmsg) {
	$t['message'] = $outmsg;
	return parse_tpl("error", $t);
}

function showeditpanel($file) {
	$f2 = $file.".z";
	removeads($file, $f2);
	$hnd = fopen($f2, "r");
	$file_contents = fread($hnd, filesize($f2));
	$basefile = basename($file);
	fclose($hnd);
	unlink($f2);
	$t['file'] = $basefile;
	$t['contents'] = $file_contents;
  return parse_tpl("manager.edit", $t);
}

function shownewfilepanel () {
	return get_raw_tpl("manager.newfile");
}

function getdisabledexts ($username) {
	$exts = getaccountinfo($username, 4);
	$disabled = split(",", $exts);
	return $disabled;
}

function changedata ($username, $index, $newvalue) {
  $f1 = file(getcwd()."/accounts.db");
  $h = fopen(getcwd()."/accounts.db", "w");
  foreach ($f1 as $l) {
    $a = split("::", $l);
    if (trim($a[0]) == trim($username)) {
      $a[$index] = $newvalue;
      $c = $a[0];
      for ($i=1;$i<count($a);$i++) {
        $c .= "::".$a[$i];
      }
      fwrite($h, $c);
    } else {
      fwrite($h, $l);
    }
  }
  fclose($h);
}

function showheader () {
	$f = file(getcwd()."/header.txt");
	$contents = "";
  foreach ($f as $l) {
    $contents .= $l;
  }
  return $contents;
}

function showfooter () {
	$f = file(getcwd()."/footer.txt");
	$contents = "";
  foreach ($f as $l) {
    $contents .= $l;
  }
  return $contents;
}

function adsexist ($file) {
	$f = file($file);
	$a1 = "<!--START THOMEPAGES HEADER ADS-->";
	$a2 = "<!--END THOMEPAGES HEADER ADS-->";
	$a3 = "<!--START THOMEPAGES FOOTER ADS-->";
	$a4 = "<!--END THOMEPAGES FOOTER ADS-->";
	$ad1 = 0;
	$ad2 = 0;
	$ad3 = 0;
	$ad4 = 0;
	foreach ($f as $l) {
	  $l = strtoupper(trim($l));
	  if ($l == $a1)
	    $ad1 = 1;
    if ($l == $a2)
	    $ad2 = 1;
    if ($l == $a3)
	    $ad3 = 1;
    if ($l == $a4)
	    $ad4 = 1;
	}
	if ($ad1 == 1 && $ad2 == 1 && $ad3 == 1 && $ad4 == 1)
	  return true;
	else
	  return false;
}

function removeads ($file, $tmpfile) {
  $f = file($file);
  $ad1 = "<!--START THOMEPAGES HEADER ADS-->";
  $ad2 = "<!--END THOMEPAGES HEADER ADS-->";
  $ad3 = "<!--START THOMEPAGES FOOTER ADS-->";
  $ad4 = "<!--END THOMEPAGES FOOTER ADS-->";
  $h = fopen($tmpfile, "w");
  $w = 1;
  foreach ($f as $l) {
    if (trim($l) == $ad1) {
      $w = 0;
    } elseif (trim($l) == $ad3) {
      $w = 0;
    }
    if ($w == 1) {
      fwrite($h, $l);
    }
    if (trim($l) == $ad2) {
      $w = 1;
    } elseif (trim($l) == $ad4) {
      $w = 1;
    }
  }
  fclose($h);
}

function insertads ($f) {
  $ad1 = "<!--START THOMEPAGES HEADER ADS-->\n";
  $ad2 = "<!--END THOMEPAGES HEADER ADS-->\n";
  $ad3 = "<!--START THOMEPAGES FOOTER ADS-->\n";
  $ad4 = "<!--END THOMEPAGES FOOTER ADS-->";
	$f1 = file($f);
	$hd = file(getcwd()."/header.inc");
	$ft = file(getcwd()."/footer.inc");
	foreach ($f1 as $l) {
	  $ct .= $l;
	}
	foreach ($hd as $l) {
	  $hdr .= $l;
	}
	foreach ($ft as $l) {
	  $ftr .= $l;
	}
	$ct = $hdr.$ct.$ftr;
	$h = fopen($f);
	fwrite($h, $ct);
	fclose($h);
}

?>
Return current item: HostBuilder