Top
Home

MAMP > bin > mamp > index.php

This file can replace the index.php found at the path



<?php

if( !function_exists('json_decode') ) {
include_once(dirname(__FILE__)."/JSON.php");
function json_decode($data) {
$json = new Services_JSON();
return( $json->decode($data) );
}
}

// available Languages
$arr_languages = (array) array('English', 'German', 'Italian', 'Japanese', 'ru', 'Spanish', 'French');
$language = (isset($_REQUEST['language'])) ? $_REQUEST['language'] : 'English';
if (!in_array($language, $arr_languages)) {
$language = 'English';
}


$transFile = dirname(__FILE__) . "/../translate/" . $language . ".json";
if (file_exists($transFile)) {
$GLOBALS["MAMP_TRANSLATE"] = json_decode(file_get_contents($transFile));
}

// get page
$page = isset($_GET["page"]) ? $_GET["page"] : "home";

// if its phpinfo use output buffering to get phpinfo code
if ($page == "phpinfo") {
ob_start();
phpinfo();
$phpinfoOrig = ob_get_contents();
ob_end_clean();
// grap contents of body tag
$phpinfo = preg_replace('%^.*<body>(.*)</body>.*$%ms', '$1', $phpinfoOrig);
}

// reset update flag
file_put_contents('feed/needsUpdate.txt', "0");


// read config file and create config object
$config = @file_get_contents(dirname(__FILE__) . "/../mamp.conf.json");
$configObject = $config ? json_decode($config) : null;

// prepare for sqlite manager
$arr_sqllite_manager_languages = (array) array('French' => '1', 'English' => '2', 'German' => '4', 'Japanese' => '5', 'Italian' => '6', 'Spanish' => '10');
setCookie('SQLiteManager_currentLangue', $arr_sqllite_manager_languages[$language], NULL, '/');

function iFrame($url) {
print '<div class="container fullheight">
<div class="tablecontainer">
<div class="tablerow">
<div class="tablecell"><iframe style="width:100%;height:100%;" src="' . $url . '"></iframe></div>
</div>
</div>
</div>';
}

function downloadFeed() {

global $language, $configObject;
$filename = "home.json";
$phpPath = getPHPCLIPath();
$phpScriptPath = realpath(dirname(__FILE__) . "/../feed/fetchFeed.php");

if(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
{
$cmd = $phpPath . ' "' . $phpScriptPath . '" ' . $configObject->app . " $language $filename > nil &";
}
else
{
$cmd = $phpPath . ' "' . $phpScriptPath . '" ' . $configObject->app . " $language $filename > /dev/null &";
}

$output = array();
$exit = 0;

exec($cmd, $output, $exit);

return $exit == 0;
}

function tr($englishText) {
$learn = false; // set to true to generate a json file with the strings of a page. At the end of the page you have to insert write_tr();
if ($learn) {
if (!isset($GLOBALS['TR_LEARN'])) {
$GLOBALS['TR_LEARN'] = array();
}

$GLOBALS['TR_LEARN'][$englishText] = $englishText;
} else if (isset($GLOBALS["MAMP_TRANSLATE"])) {
if (isset($GLOBALS["MAMP_TRANSLATE"]->$englishText)) {
return $GLOBALS["MAMP_TRANSLATE"]->$englishText;
}
}

return $englishText;
}

function write_tr() {
if (isset($GLOBALS['TR_LEARN'])) {
$tr_file = json_encode($GLOBALS['TR_LEARN'], JSON_PRETTY_PRINT);
file_put_contents(str_replace(".", "_", basename(__FILE__)) . "_tr.json", $tr_file);
}
}

// returns true if $needle is a substring of $haystack
function contains($needle, $haystack)
{
return strpos($haystack, $needle) !== false;
}

function getPHPCLIPath() {
$vistaornewwer = true;

$osver = php_uname();

if(contains("Windows NT 5.1", $osver) || contains("Windows XP", $osver))
{
//windows xp
$vistaornewwer = false;
}
else if(contains("Windows NT 5.2", $osver))
{
//windows 2003
$vistaornewwer = false;
}
else if(contains("Windows NT 5.0", $osver) || contains("Windows 2000", $osver))
{
//windows 2000
$vistaornewwer = false;
}

if((strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'))
{
$path = realpath(__DIR__ . DIRECTORY_SEPARATOR .'../../php');
}
else
{
$path = "/Applications/MAMP/bin/php";
}

$folder = "";

$d = dir($path);

while (false !== ($entry = $d->read())) {
if((strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'))
{
if (substr($entry, 0, 3) == "php" && is_dir($path . "\" . $entry)) {
if ($entry > $folder) {
if($entry > 'php5.4.9' && ($vistaornewwer==false))
{
//do not set php folder
}
else
{
$folder = $entry;
}
}
}
}
else
{
if (substr($entry, 0, 3) == "php" && is_dir($path . "/" . $entry)) {
if ($entry > $folder) {
$folder = $entry;
}
}
}
}
$d->close();

if ($folder === "") {
return false;
}

if((strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'))
{
$execpath = $path . "/" . $folder . "/php.exe";
}
else
{
$execpath = $path . "/" . $folder . "/bin/php";
}

return $execpath;
}

function getFeed() {
global $language;
$feedName = "home.json";
$feedPath = 'feed/' . $language . '/' . $feedName;
$feed = null;
$path = realpath(dirname(__FILE__) . "/../" . $feedPath);
if (file_exists($path)) {
$json = file_get_contents($path);
$feed = json_decode($json);
}
return $feed;
}

function createItemsForCarouselFromFeedObject($feed) {
global $configObject;
$items = array();
if (isset($feed->carousel)) {
foreach ($feed->carousel->all as $item) {
$items[] = $item;
}
if (!is_bought()) {
foreach ($feed->carousel->buy as $item) {
$items[] = $item;
}
}
$parts = explode(".", $feed->currentVersion);

if (isset($parts[0])) {
$majorversion = $parts[0];
$currVer = $configObject->version;
$parts = explode(".", $currVer);
if (isset($parts[0])) {
$majorversionCurrent = $parts[0];
if (abs($majorversion) > abs($majorversionCurrent)) {
foreach ($feed->carousel->upgrade as $item) {
$items[] = $item;
}
}
}
}
}
return $items;
}

// checks if user has bought mamp
function is_bought() {
global $configObject;
if ($configObject->app == "MAMP") {
return false;
}
$i_bought = false;
if (file_exists(dirname(__FILE__) . '/../bought')) {
$i_bought = (int) file_get_contents(dirname(__FILE__) . '/../bought');
}
return $i_bought;
}

function appName() {
global $configObject;

if ($configObject->app == "MAMPPRO") {
return "MAMP PRO";
}
return "MAMP";
}

function a($page) {
global $language;
return '<a href="index.php?page=' . $page . '&amp;language=' . $language . '">';
}

function buyLink()
{
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
return "http://www.mamp.info/winstore";
} else {
return "http://www.mamp.info/macstore";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="../../docs-assets/ico/favicon.png">

<title><?php echo appName(); ?></title>

<!-- Bootstrap core CSS -->
<link href="css/bootstrap.css" rel="stylesheet">

<link href="css/style.css" rel="stylesheet">

<?php if($page == "home" || $page == "faq") {
if(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
{
include_once('../phpMyAdmin/config.inc.php');
}
else
{
if ($configObject->app == "MAMP")
{
include_once('/Applications/MAMP/bin/phpMyAdmin/config.inc.php');
}
else
{
include_once('/Library/Application Support/appsolute/MAMP PRO/phpMyAdmin/config.inc.php');
}
}
?>
<link href="css/screen.css" rel="stylesheet">
<?php } else if($page == "phpinfo") { ?>
<style>
table {border-collapse: collapse;}
.center {text-align: center;}
.center table { margin-left: auto; margin-right: auto; text-align: left;}
.center th { text-align: center !important; }
td, th { border: 1px solid #000000; font-size: 75%; vertical-align: baseline;}
h1 {font-size: 150%;}
h2 {font-size: 125%;}
.p {text-align: left;}
.e {background-color: #ccccff; font-weight: bold; color: #000000;}
.h {background-color: #9999cc; font-weight: bold; color: #000000;}
.v {background-color: #cccccc; color: #000000;}
.vr {background-color: #cccccc; text-align: right; color: #000000;}
img {float: right; border: 0px;}
hr {width: 600px; background-color: #cccccc; border: 0px; height: 1px; color: #000000;}
</style>
<?php } ?>
</head>
<!-- NAVBAR
================================================== -->
<body>
<div class="navbar-wrapper">
<div class="container">
<div class="navbar navbar-inverse navbar-static-top" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li<?php if($page=="home") { ?> class="active"<?php } ?>><a href="index.php?language=<?php echo $language; ?>"><?php echo tr("Start"); ?></a></li>
<?php $myWebsite='http://localhost:8888'; if($myWebsite!='') { echo '<li><a class="navbar-brand" href="' . $myWebsite . '" target="_blank">' . tr('My Website') . '</a></li>'; } ?>

<li<?php if (strpos('apc eaccelerator xcache phpmyadmin sqlitemanager phpliteadmin', $page) !== false) { ?> class="active dropdown"<?php } else { ?> class="dropdown" <?php } ?>>
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><?php echo tr("Tools") ?> <b class="caret"></b></a>
<ul class="dropdown-menu">
<?php if(extension_loaded('apc')): ?>
<li<?php if($page=="apc") { ?> class="active"<?php } ?>><a target="_blank" href="<?php echo "apc.php"; ?>">APC</a></li> <?php endif ?>
<?php if(extension_loaded('eAccelerator')): ?>
<li<?php if($page=="eaccelerator") { ?> class="active"<?php } ?>><a target="_blank" href="<?php echo "eaccelerator.php"; ?>">eAccelerator</a></li> <?php endif ?>
<?php if(extension_loaded('XCache')): ?>
<li<?php if($page=="xcache") { ?> class="active"<?php } ?>><a target="_blank" href="<?php echo "xcache-admin/"; ?>">XCache</a></li> <?php endif ?>
<?php if(version_compare(PHP_VERSION, '5.3.0', '>=')) { ?>
<li<?php if($page=="phpmyadmin") { ?> class="active"<?php } ?>><a target="_blank" href="<?php echo "phpmyadmin.php?lang=".tr("phpMyAdminLanguage"); ?>">phpMyAdmin</a></li> <?php } ?>
<?php if(version_compare(PHP_VERSION, '5.2.0', '>=') and version_compare(PHP_VERSION, '5.4.0', '<')) { ?>
<li<?php if($page=="sqlitemanager") { ?> class="active"<?php } ?>><a target="_blank" href="<?php echo "/SQLiteManager/"; ?>">SQLite Manager</a></li> <?php } ?>
<li<?php if($page=="phpliteadmin") { ?> class="active"<?php } ?>><a target="_blank" href="<?php echo "/phpLiteAdmin/"; ?>">phpLiteAdmin</a></li> </ul>
</li>
<li><a class="navbar-brand" href="http://Mooseloose.com" target="_blank">Moose Loose</a></li>
<li><a class="navbar-brand" href="http://MooseZoo.tumblr.com" target="_blank">Moose Zoo</a></li>
<?php $myFavLink=''; if($myFavLink!='') { echo '<li><a class="navbar-brand" href="' . $myFavLink . '" target="_blank">' . tr('My favorite Link') . '</a></li>'; } ?>
</ul><!-- end left -->
<ul class="nav navbar-nav navbar-right">

</ul><!-- end right -->
</div><!-- end collapse -->
</div><!-- end navbar -->
</div><!-- end container -->
</div><!-- end navbar-wrapper -->

<?php if($page == "phpinfo") { ?>
<div class="top85">
<?php echo $phpinfo; ?>
</div>
<?php } else if($page == "phpmyadmin") { ?>
<?php print iFrame("phpmyadmin.php?lang=".tr("phpMyAdminLanguage")); ?>
<?php } else if($page == "sqlitemanager") { ?>
<?php print iFrame("/SQLiteManager/"); ?>
<?php } else if($page == "phpliteadmin") { ?>
<?php print iFrame("/phpLiteAdmin/"); ?>
<?php } else if($page == "apc") { ?>
<?php print iFrame("apc.php"); ?>
<?php } else if($page == "eaccelerator") { ?>
<?php print iFrame("eaccelerator.php"); ?>
<?php } else if($page == "xcache") { ?>
<?php print iFrame("xcache-admin/"); ?>
<?php } else if ($page == "faq") { ?>

<div class="container top85">
<div class="frame">
<h1><?php echo tr("FAQ"); ?></h1>
<dl>
<dt><?php echo tr("Which programs are installed?"); ?></dt>
<dd><ul>
<?php
$faqPath = "includes/faq_".$configObject->app.".php";
foreach ($configObject->components as $component)
{
echo '<li>'.htmlspecialchars($component->name)." ".htmlspecialchars($component->version),'</li>';
}?>
</ul></dd>
<?php include($faqPath); ?>
</dl>
</div>
</div>

<?php } else { ?>





</div>

<?php } ?>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<?php if($page == "home") { ?>
<script type="text/javascript">

function checkNeedsUpdate()
{
$.get( "feed/needsUpdate.txt", function( data ) {
if (data == 1)
{
location.reload();
}});
}

setTimeout(function(){checkNeedsUpdate();},2000);

</script>
<?php } ?>
</body>
</html>
<?php

downloadFeed();
write_tr();

?>