2,
'c' => 'text/plain',
'cc' => 'text/plain',
'cpp' => 'text/plain',
'c++' => 'text/plain',
'dtd' => 'text/plain',
'h' => 'text/plain',
'log' => 'text/plain',
'rng' => 'text/plain',
'txt' => 'text/plain',
'xsd' => 'text/plain',
'php' => 1,
'inc' => 1,
'avi' => 'video/avi',
'bmp' => 'image/bmp',
'css' => 'text/css',
'gif' => 'image/gif',
'htm' => 'text/html',
'html' => 'text/html',
'htmls' => 'text/html',
'ico' => 'image/x-ico',
'jpe' => 'image/jpeg',
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'js' => 'application/x-javascript',
'midi' => 'audio/midi',
'mid' => 'audio/midi',
'mod' => 'audio/mod',
'mov' => 'movie/quicktime',
'mp3' => 'audio/mp3',
'mpg' => 'video/mpeg',
'mpeg' => 'video/mpeg',
'pdf' => 'application/pdf',
'png' => 'image/png',
'swf' => 'application/shockwave-flash',
'tif' => 'image/tiff',
'tiff' => 'image/tiff',
'wav' => 'audio/wav',
'xbm' => 'image/xbm',
'xml' => 'text/xml',
);
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
$basename = basename(__FILE__);
if (!strpos($_SERVER['REQUEST_URI'], $basename)) {
chdir(Extract_Phar::$temp);
include $web;
return;
}
$pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename));
if (!$pt || $pt == '/') {
$pt = $web;
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt);
exit;
}
$a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt);
if (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) {
header('HTTP/1.0 404 Not Found');
echo "\n
\n File Not Found\n \n \n 404 - File Not Found
\n \n";
exit;
}
$b = pathinfo($a);
if (!isset($b['extension'])) {
header('Content-Type: text/plain');
header('Content-Length: ' . filesize($a));
readfile($a);
exit;
}
if (isset($mimes[$b['extension']])) {
if ($mimes[$b['extension']] === 1) {
include $a;
exit;
}
if ($mimes[$b['extension']] === 2) {
highlight_file($a);
exit;
}
header('Content-Type: ' .$mimes[$b['extension']]);
header('Content-Length: ' . filesize($a));
readfile($a);
exit;
}
}
class Extract_Phar
{
static $temp;
static $origdir;
const GZ = 0x1000;
const BZ2 = 0x2000;
const MASK = 0x3000;
const START = 'app.php';
const LEN = 6673;
static function go($return = false)
{
$fp = fopen(__FILE__, 'rb');
fseek($fp, self::LEN);
$L = unpack('V', $a = (binary)fread($fp, 4));
$m = (binary)'';
do {
$read = 8192;
if ($L[1] - strlen($m) < 8192) {
$read = $L[1] - strlen($m);
}
$last = (binary)fread($fp, $read);
$m .= $last;
} while (strlen($last) && strlen($m) < $L[1]);
if (strlen($m) < $L[1]) {
die('ERROR: manifest length read was "' .
strlen($m) .'" should be "' .
$L[1] . '"');
}
$info = self::_unpack($m);
$f = $info['c'];
if ($f & self::GZ) {
if (!function_exists('gzinflate')) {
die('Error: zlib extension is not enabled -' .
' gzinflate() function needed for zlib-compressed .phars');
}
}
if ($f & self::BZ2) {
if (!function_exists('bzdecompress')) {
die('Error: bzip2 extension is not enabled -' .
' bzdecompress() function needed for bz2-compressed .phars');
}
}
$temp = self::tmpdir();
if (!$temp || !is_writable($temp)) {
$sessionpath = session_save_path();
if (strpos ($sessionpath, ";") !== false)
$sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1);
if (!file_exists($sessionpath) || !is_dir($sessionpath)) {
die('Could not locate temporary directory to extract phar');
}
$temp = $sessionpath;
}
$temp .= '/pharextract/'.basename(__FILE__, '.phar');
self::$temp = $temp;
self::$origdir = getcwd();
@mkdir($temp, 0777, true);
$temp = realpath($temp);
if (!file_exists($temp . DIRECTORY_SEPARATOR . md5_file(__FILE__))) {
self::_removeTmpFiles($temp, getcwd());
@mkdir($temp, 0777, true);
@file_put_contents($temp . '/' . md5_file(__FILE__), '');
foreach ($info['m'] as $path => $file) {
$a = !file_exists(dirname($temp . '/' . $path));
@mkdir(dirname($temp . '/' . $path), 0777, true);
clearstatcache();
if ($path[strlen($path) - 1] == '/') {
@mkdir($temp . '/' . $path, 0777);
} else {
file_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp));
@chmod($temp . '/' . $path, 0666);
}
}
}
chdir($temp);
if (!$return) {
include self::START;
}
}
static function tmpdir()
{
if (strpos(PHP_OS, 'WIN') !== false) {
if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) {
return $var;
}
if (is_dir('/temp') || mkdir('/temp')) {
return realpath('/temp');
}
return false;
}
if ($var = getenv('TMPDIR')) {
return $var;
}
return realpath('/tmp');
}
static function _unpack($m)
{
$info = unpack('V', substr($m, 0, 4));
$l = unpack('V', substr($m, 10, 4));
$m = substr($m, 14 + $l[1]);
$s = unpack('V', substr($m, 0, 4));
$o = 0;
$start = 4 + $s[1];
$ret['c'] = 0;
for ($i = 0; $i < $info[1]; $i++) {
$len = unpack('V', substr($m, $start, 4));
$start += 4;
$savepath = substr($m, $start, $len[1]);
$start += $len[1];
$ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24)));
$ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3]
& 0xffffffff);
$ret['m'][$savepath][7] = $o;
$o += $ret['m'][$savepath][2];
$start += 24 + $ret['m'][$savepath][5];
$ret['c'] |= $ret['m'][$savepath][4] & self::MASK;
}
return $ret;
}
static function extractFile($path, $entry, $fp)
{
$data = '';
$c = $entry[2];
while ($c) {
if ($c < 8192) {
$data .= @fread($fp, $c);
$c = 0;
} else {
$c -= 8192;
$data .= @fread($fp, 8192);
}
}
if ($entry[4] & self::GZ) {
$data = gzinflate($data);
} elseif ($entry[4] & self::BZ2) {
$data = bzdecompress($data);
}
if (strlen($data) != $entry[0]) {
die("Invalid internal .phar file (size error " . strlen($data) . " != " .
$stat[7] . ")");
}
if ($entry[3] != sprintf("%u", crc32((binary)$data) & 0xffffffff)) {
die("Invalid internal .phar file (checksum error)");
}
return $data;
}
static function _removeTmpFiles($temp, $origdir)
{
chdir($temp);
foreach (glob('*') as $f) {
if (file_exists($f)) {
is_dir($f) ? @rmdir($f) : @unlink($f);
if (file_exists($f) && is_dir($f)) {
self::_removeTmpFiles($f, getcwd());
}
}
}
@rmdir($temp);
clearstatcache();
chdir($origdir);
}
}
Extract_Phar::go();
__HALT_COMPILER(); ?>
mda.phar app.php B` X Download.phpN B`N 1
config.ini B` Bo<
Colors.php
B`
E* interactiveDownload();
longopts);
if (isset($options['help']))
$this->usage();
$this->cwd = getcwd();
$this->colors = new Colors();
$this->localConfigFile = $this->cwd . '/.config.ini';
if (!file_exists($this->localConfigFile))
copy('phar://mda.phar/config.ini', $this->localConfigFile);
$this->config = @parse_ini_file('.config.ini');
foreach (['id', 'token', 'filter'] as $value) {
if (!empty($options[$value]))
$this->config[strtoupper($value)] = $options[$value];
}
foreach (['ID', 'TOKEN'] as $requiredField) {
if (!isset($this->config[$requiredField]))
throw new Exception(sprintf('Magento %s is not set', $requiredField));
}
$this->cacheFile = $this->cwd . '/.mda.' . sha1(serialize($this->config));
$url = sprintf($this->downloadUrlFormat, $this->config['ID'], $this->config['TOKEN']);
$url = sprintf('%s/info/json', $url);
// Fetch list of possible downloads
$downloadUrl = sprintf('%s/info/json/', $url);
if (file_exists($this->cacheFile) && (time()-filemtime($this->cacheFile) < 3600)) {
$downloadsJson = file_get_contents($this->cacheFile);
} else if ($downloadsJson = file_get_contents($downloadUrl)) {
file_put_contents($this->cacheFile, $downloadsJson);
} else {
printf("Error: Could not fetch URL (%s)\n", $url);
exit(1);
}
$this->downloadData = json_decode($downloadsJson, true);
if (!is_dir($this->downloadDir))
@mkdir($this->downloadDir);
}
public function usage()
{
echo <<downloadUrlFormat, $this->config['ID'], $this->config['TOKEN']);
$sourceFile = sprintf('%s/file/%s', $url, $filename);
if (!$destinationFile)
$destinationFile = sprintf('%s/%s/%s', $this->cwd, $this->downloadDir, $filename);
$filesize = $this->getRemoteFileSize($sourceFile);
$filesizeMb = round($filesize / 1024 / 1024, 2);
printf("Downloading from %s\n", $sourceFile);
if ($filesize == 0) {
printf("Does the remote file exist? File size is 0, cannot download");
return false;
}
if (file_exists($destinationFile) && filesize($destinationFile) == $filesize) {
printf("\nFile already downloaded\n");
return $destinationFile;
}
$remote = fopen($sourceFile, 'r');
$local = fopen($destinationFile, 'w');
$readBytes = 0;
$startTime = time();
$bufferBytes = 2048;
while (!feof($remote)) {
$buffer = fread($remote, $bufferBytes);
fwrite($local, $buffer);
$readBytes += $bufferBytes;
$progress = round(100 * $readBytes / $filesize, 0);
$seconds = time() - $startTime;
$mbps = 0;
if ($seconds > 0)
$mbps = round(( $readBytes / 1024 / 1024 ) / $seconds, 2);
echo str_pad(sprintf("%s %s%% of %sMB (%s MB/s)", $msgPrefix, $progress, $filesizeMb, $mbps), 40)."\r";
}
fclose($remote);
fclose($local);
return $destinationFile;
}
public function remoteFileExists($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$result = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return ($result == 200) ? true : false;
}
public function getRemoteFileSize($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$data = curl_exec($ch);
curl_close($ch);
if (preg_match('/Content-Length: (\d+)/i', $data, $matches))
$contentLength = (int)$matches[1];
return $contentLength;
}
public function downloadEefull()
{
return $this->downloadFull('ee-full');
}
public function downloadCefull()
{
return $this->downloadFull('ce-full');
}
public function downloadFull($magentoVersion = 'ce-full')
{
uksort($this->downloadData[$magentoVersion], 'version_compare');
// Show all full releases
system('clear');
$this->printLog();
printf("Download full releases\n--\n\n");
$all = false;
$id = 0;
$downloadMap = [];
foreach ($this->downloadData[$magentoVersion] as $version => $releases) {
$downloadMap[$id] = $version;
$option = sprintf(" [%d]:", $id++);
printf("%s %s\n", str_pad($option, 8), $version);
}
$downloadMap['a'] = 'a';
$downloadMap['q'] = 'q';
printf("\n [a]: All downloads\n");
printf("\n [q]: Quit\n");
$downloadVersion = -1;
while (!array_key_exists($downloadVersion, $downloadMap)) {
$downloadVersion = readline("\nSelect a valid option: ");
}
$downloadRelease = $downloadMap[$downloadVersion];
// Show all versions for selected release
system('clear');
$this->printLog();
$downloadReleases = [ $downloadRelease ];
switch ($downloadRelease) {
case 'a':
$remove = preg_grep('/[^0-9]+/', array_keys($downloadMap));
$downloadReleases = array_diff_key($downloadMap, array_flip($remove));
$all = true;
break;
case 'q':
exit;
break;
}
foreach ($downloadReleases as $downloadRelease) {
printf("Download %s\n--\n\n", $downloadRelease);
$id = 0;
$downloadMap = [];
foreach ($this->downloadData[$magentoVersion][$downloadRelease] as $release) {
$downloadMap[$id] = $release['file_name'];
$option = sprintf(" [%d]:", $id++);
$row = sprintf("%s %s\n", str_pad($option, 8), $release['name']);
if (!$all)
echo $row;
}
$downloadMap['a'] = 'a';
$downloadMap['q'] = 'q';
if (!$all)
printf("\n [a]: All downloads\n");
printf("\n [q]: Quit\n");
if (!$all) {
$downloadVersion = -1;
while (!array_key_exists($downloadVersion, $downloadMap)) {
$downloadVersion = readline("\nSelect a valid option: ");
}
$downloadFilename = $downloadMap[$downloadVersion];
} else {
$downloadFilename = 'a';
}
system('clear');
$this->printLog();
$downloadFilenames = [ $downloadFilename ];
switch ($downloadFilename) {
case 'a':
$remove = preg_grep('/[^0-9]+/', array_keys($downloadMap));
$downloadFilenames = array_diff_key($downloadMap, array_flip($remove));
$all = true;
break;
case 'q':
exit;
break;
}
foreach ($downloadFilenames as $downloadFilename) {
printf("\nDownloading %s\n--\n\n", $downloadFilename);
$downloadFile = sprintf('%s/%s/%s', $this->cwd, $this->downloadDir, $downloadFilename);
if ($all && preg_match('/(Samples|sample_data)/', $downloadFile)) {
$this->log[] = sprintf("Downloads including sample data skipped when downloading all\r\n");
} else if (!empty($this->config['FILTER']) && !preg_match('#'.$this->config['FILTER'].'#i', $downloadFile)) {
$this->log[] = sprintf("Filename does not match filter, skipped\r\n");
} else if ($destinationFile = $this->download($downloadFilename, $downloadFile)) {
$this->log[] = sprintf("File downloaded to %s\r\n", $destinationFile);
} else {
$this->log[] = sprintf("Download Failed\r\n");
}
}
}
$this->downloadFull($magentoVersion);
}
public function downloadOther()
{
uksort($this->downloadData['other'], 'version_compare');
// Show all full releases
system('clear');
$this->printLog();
printf("Download other files\n--\n\n");
$id = 0;
$downloadMap = [];
foreach ($this->downloadData['other'] as $version => $releases) {
$downloadMap[$id] = $releases['file_name'];
$option = sprintf(" [%d]:", $id++);
printf("%s %s\n", str_pad($option, 8), $releases['name']);
}
$downloadMap['a'] = 'a';
$downloadMap['q'] = 'q';
printf("\n [a]: All downloads\n");
printf("\n [q]: Quit\n");
$downloadVersion = -1;
while (!array_key_exists($downloadVersion, $downloadMap)) {
$downloadVersion = readline("\nSelect a valid option: ");
}
$downloadFilename = $downloadMap[$downloadVersion];
system('clear');
$this->printLog();
$downloadFilenames = [ $downloadFilename ];
switch ($downloadFilename) {
case 'a':
$remove = preg_grep('/[^0-9]+/', array_keys($downloadMap));
$downloadFilenames = array_diff_key($downloadMap, array_flip($remove));
$all = true;
break;
case 'q':
exit;
break;
}
foreach ($downloadFilenames as $downloadFilename) {
printf("Downloading %s\n--\n\n", $downloadFilename);
$downloadFile = sprintf('%s/%s/%s', $this->cwd, $this->downloadDir, $downloadFilename);
if ($destinationFile = $this->download($downloadFilename, $downloadFile)) {
$this->log[] = sprintf("File downloaded to %s\r\n", $destinationFile);
} else {
$this->log[] = sprintf("Download Failed\r\n");
}
}
$this->downloadOther();
}
public function downloadEePatch()
{
return $this->downloadPatch(false, 'ee-patch');
}
public function downloadCePatch()
{
return $this->downloadPatch(false, 'ce-patch');
}
public function downloadPatch($downloadRelease = false, $magentoVersion = 'ce-patch', $autoDetectedVersion = false)
{
uksort($this->downloadData[$magentoVersion], 'version_compare');
// Show all full releases
system('clear');
printf("Download Magento patches\n--\n\n");
$id = 0;
$downloadMap = [];
// Attempt to auto detect Magento version
if (!$downloadRelease) {
$mageFilename = sprintf("%s/app/Mage.php", $this->cwd);
if (file_exists($mageFilename)) {
require_once getcwd().'/app/Mage.php';
$versionArray = Mage::getVersionInfo();
$versionString = sprintf("%s.%s.%s.%s", $versionArray['major'], $versionArray['minor'], $versionArray['revision'], $versionArray['patch']);
$downloadMap[$id] = $versionString;
$autoDetectedVersion = $versionString;
printf(" [%d]: %s %s\n", $id++, $versionString, $this->colors->getColoredString('(auto detected)', 'green'));
}
foreach ($this->downloadData[$magentoVersion] as $version => $releases) {
$downloadMap[$id] = $version;
printf(" [%d]: %s\n", $id++, $version);
}
$downloadMap['a'] = 'a';
$downloadMap['q'] = 'q';
printf("\n [a]: All downloads\n");
printf("\n [q]: Quit\n");
$downloadVersion = -1;
while (!array_key_exists($downloadVersion, $downloadMap)) {
$downloadVersion = readline("\nSelect a valid option: ");
}
$downloadRelease = $downloadMap[$downloadVersion];
}
$appliedFilename = sprintf("%s/app/etc/applied.patches.list", $this->cwd);
$appliedPatches = [];
if (file_exists($appliedFilename)) {
$content = file_get_contents($appliedFilename);
if (preg_match_all('/^[a-zA-Z0-9:\s\-]+ \| ([^\|]+) \| ([^\|]+) \| ([^\|]+) \|/m', $content, $matches)) {
foreach ($matches[0] as $key => $value) {
$patchName = preg_replace(['/^[A-Z_-]+[_-]SUPEE/', '/(SUPEE-[0-9.]+)[_-].+/'], ['SUPEE', '\\1'], trim($matches[1][$key]));
$magentoRelease = trim($matches[2][$key]);
$patchVersion = trim($matches[3][$key]);
//$appliedPatches[] = $patchName;
$appliedPatches[] = sprintf('%s-%s', $patchName, $patchVersion);
//$appliedPatches[] = $matches[1][$key];
}
}
}
// Show all patches for selected release
system('clear');
$this->printLog();
$downloadReleases = [ $downloadRelease ];
switch ($downloadRelease) {
case 'a':
$remove = preg_grep('/[^0-9]+/', array_keys($downloadMap));
$downloadReleases = array_diff_key($downloadMap, array_flip($remove));
$all = true;
break;
case 'q':
exit;
break;
}
foreach ($downloadReleases as $downloadRelease) {
printf("Patches for Magento %s\n--\n\n", $downloadRelease);
$id = 0;
$downloadMap = [];
$missingPatches = [];
if (is_array($this->downloadData[$magentoVersion][$downloadRelease])) {
foreach ($this->downloadData[$magentoVersion][$downloadRelease] as $release) {
$downloadMap[$id] = $release['file_name'];
$nameArray = explode(' ', $release['name']);
$shortName = array_shift($nameArray);
$patchVersion = (preg_match('/(v[0-9.]+)/', $release['file_name'], $matches)) ? rtrim($matches[1], '.') : 'v1';
$patchReleaseVersion = (preg_match('/(v[0-9.]+)_(v[0-9.]+)/', $release['file_name'], $matches)) ? rtrim($matches[2], '.') : 'v1';
$patchName = (preg_match('/(SUPEE-[0-9]+)/', $release['file_name'], $matches))
? $matches[1]
: (preg_match('/(SUPEE-[0-9]+)/', $release['name'], $matches))
? $matches[1]
: '';
$patchCombinedName = sprintf('%s-%s', $patchName, $patchVersion);
$patchReleaseCombinedName = sprintf('%s-%s', $patchName, $patchReleaseVersion);
if (!$all) {
$status = false;
if ($autoDetectedVersion == $downloadRelease) {
if (in_array($release['file_name'], $appliedPatches) ||
in_array($patchName, $appliedPatches) ||
in_array($patchCombinedName, $appliedPatches) ||
in_array($patchReleaseCombinedName, $appliedPatches)) {
$status = $this->colors->getColoredString(str_pad('Installed', 12), 'green');
} else {
$status = $this->colors->getColoredString(str_pad('Missing', 12), 'red');
$missingPatches[] = $release['file_name'];
}
}
$option = sprintf(" [%d]:", $id++);
printf("%s %s%s (%s/%s)\n", str_pad($option, 8), $status, $release['name'], $release['file_name'], $shortName);
}
}
if (!$all) {
$downloadMap['a'] = 'a';
printf("\n [a]: All patches");
}
$downloadMap['m'] = 'm';
printf("\n [m]: All missing patches\n");
}
$downloadMap['q'] = 'q';
printf("\n [q]: Quit\n");
if (!$all) {
$downloadVersion = -1;
while (!array_key_exists($downloadVersion, $downloadMap)) {
$downloadVersion = readline("\nSelect a valid option: ");
}
$downloadFilename = $downloadMap[$downloadVersion];
} else {
$downloadFilename = 'a';
}
system('clear');
$this->printLog();
$downloadFilenames = [ $downloadFilename ];
switch ($downloadFilename) {
case 'a':
$remove = preg_grep('/[^0-9]+/', array_keys($downloadMap));
$downloadFilenames = array_diff_key($downloadMap, array_flip($remove));
break;
case 'm':
$downloadFilenames = $missingPatches;
break;
case 'q':
exit;
break;
}
foreach ($downloadFilenames as $downloadFilename) {
printf("Downloading %s\n--\n\n", $downloadFilename);
$downloadFile = sprintf('%s/%s/%s', $this->cwd, $this->downloadDir, $downloadFilename);
if ($destinationFile = $this->download($downloadFilename, $downloadFile)) {
$this->log[] = sprintf("File downloaded to %s\r\n", $destinationFile);
} else {
$this->log[] = sprintf("Download Failed\r\n");
}
}
}
$this->downloadPatch($downloadRelease, $magentoVersion, $autoDetectedVersion);
}
public function printLog()
{
if (!count($this->log))
return;
printf("Download Log\n--\n\n");
foreach ($this->log as $log) {
printf(" > %s", $log);
}
printf("\n\n");
}
public function interactiveDownload()
{
system('clear');
$downloadType = -1;
$downloadDataKeys = array_keys($this->downloadData);
// Show different download types
system('clear');
printf("Downloadable types\n--\n\n");
foreach ($downloadDataKeys as $id => $optionText) {
$option = sprintf(" [%d]:", $id);
printf("%s %s\n", str_pad($option, 8), ucfirst($optionText));
}
$downloadDataKeys['q'] = 'q';
printf("\n [q]: Quit\n");
while (!array_key_exists($downloadType, $downloadDataKeys)) {
$downloadType = readline("\nSelect a valid option: ");
}
$downloadType = $downloadDataKeys[$downloadType];
$downloadMethod = sprintf('download%s', ucfirst(str_replace('-', '', $downloadType)));
switch ($downloadType) {
case 'q':
exit;
break;
}
$this->{$downloadMethod}();
}
}
# Adjust to suit your username and password for your account on magentocommerce.com
# Or just leave defaults in place
ID="MAG003125809"
TOKEN="ac348f9fc0451063ec60bf486ebbf9fa2c7b9ad0"
foreground_colors['black'] = '0;30';
$this->foreground_colors['dark_gray'] = '1;30';
$this->foreground_colors['blue'] = '0;34';
$this->foreground_colors['light_blue'] = '1;34';
$this->foreground_colors['green'] = '0;32';
$this->foreground_colors['light_green'] = '1;32';
$this->foreground_colors['cyan'] = '0;36';
$this->foreground_colors['light_cyan'] = '1;36';
$this->foreground_colors['red'] = '0;31';
$this->foreground_colors['light_red'] = '1;31';
$this->foreground_colors['purple'] = '0;35';
$this->foreground_colors['light_purple'] = '1;35';
$this->foreground_colors['brown'] = '0;33';
$this->foreground_colors['yellow'] = '1;33';
$this->foreground_colors['light_gray'] = '0;37';
$this->foreground_colors['white'] = '1;37';
$this->background_colors['black'] = '40';
$this->background_colors['red'] = '41';
$this->background_colors['green'] = '42';
$this->background_colors['yellow'] = '43';
$this->background_colors['blue'] = '44';
$this->background_colors['magenta'] = '45';
$this->background_colors['cyan'] = '46';
$this->background_colors['light_gray'] = '47';
}
// Returns colored string
public function getColoredString($string, $foreground_color = null, $background_color = null) {
$colored_string = "";
// Check if given foreground color found
if (isset($this->foreground_colors[$foreground_color])) {
$colored_string .= "\033[" . $this->foreground_colors[$foreground_color] . "m";
}
// Check if given background color found
if (isset($this->background_colors[$background_color])) {
$colored_string .= "\033[" . $this->background_colors[$background_color] . "m";
}
// Add string and end coloring
$colored_string .= $string . "\033[0m";
return $colored_string;
}
// Returns all foreground color names
public function getForegroundColors() {
return array_keys($this->foreground_colors);
}
// Returns all background color names
public function getBackgroundColors() {
return array_keys($this->background_colors);
}
}
?>nrU۹_Ƥ>* GBMB