Last active
August 19, 2016 23:51
-
-
Save kazumich/7f1c477bfd9497c0ed14f1e9d3ddcfdd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html lang="ja"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>a-blog cms インストーラー (MAMP版)</title> | |
</head> | |
<body> | |
<?php | |
set_time_limit(0); | |
// -------------------------- | |
// | |
// MAMP用 a-blog cms インストーラー | |
// | |
// -------------------------- | |
$dbHost = 'localhost'; | |
$dbName = 'DBacms'; | |
$dbCreate = 'checked'; | |
$dbUser = 'root'; | |
$dbPass = 'root'; | |
// -------------------------- | |
// a-blog cms Ver. 2.6.1.3 設定 | |
// -------------------------- | |
# ダウンロード元 URL | |
$download55 = "http://www.a-blogcms.jp/_download/2613/php53x/acms2613_install_53x.zip"; | |
$download56 = "http://www.a-blogcms.jp/_download/2613/php56x/acms2613_install_56x.zip"; | |
# ダウンロード後のZipファイル名 | |
$zipFile = "./acms2613_install.zip"; | |
# 解凍後の全体フォルダ名 | |
$zipAfterDirName55 = "acms2613_install_53x"; | |
$zipAfterDirName56 = "acms2613_install_56x"; | |
# 解凍後の a-blog cms のフォルダ名 | |
$cmsDirName = "ablogcms"; | |
# ioncube Loader ダウンロード元 URL | |
$downloadIoncube = "http://downloads3.ioncube.com/loader_downloads/ioncube_loaders_dar_x86-64.zip"; | |
# ioncube Loader ダウンロード後のZipファイル名 | |
$zipFileIoncube ="ioncube.zip"; | |
$installPath = realpath('.'); | |
$phpName = basename($_SERVER['PHP_SELF']); | |
// -------------------------- | |
// バージョンのチェック | |
// -------------------------- | |
$versionArray = explode(".", phpversion()); | |
$version = $versionArray[0].".".$versionArray[1]; | |
if ($versionArray[0] == 7) { | |
echo '<p style="text-align:center; margin-top:100px">現在、a-blog cms は PHP 7 に対応しておりません。MAMP の設定... から PHP のバージョンを変更ください。</p>'; | |
exit; | |
} | |
if ($versionArray[1] >= 6) { | |
$download = $download56; | |
$zipAfterDirName = $zipAfterDirName56; | |
} else { | |
$download = $download55; | |
$zipAfterDirName = $zipAfterDirName55; | |
} | |
$ablogcmsDir = $installPath."/".$zipAfterDirName."/".$cmsDirName."/"; | |
// -------------------------- | |
// a-blog cms ファイルをダウンロード | |
// -------------------------- | |
$fp = fopen($download, "r"); | |
if ($fp !== FALSE) { | |
file_put_contents($zipFile, ""); | |
while(!feof($fp)) { | |
$buffer = fread($fp, 4096); | |
if ($buffer !== FALSE) { | |
file_put_contents($zipFile, $buffer, FILE_APPEND); | |
} | |
} | |
fclose($fp); | |
} else { | |
echo 'a-blog cms download Error ! : '.$download; | |
exit; | |
} | |
// -------------------------- | |
// a-blog cms ファイルを解凍 | |
// -------------------------- | |
$zip = new ZipArchive(); | |
$res = $zip->open($zipFile); | |
if($res === true){ | |
$zip->extractTo($installPath); | |
$zip->close(); | |
} else { | |
echo 'a-blog cms unZip Error ! : '. $zipFile; | |
exit; | |
} | |
// -------------------------- | |
// a-blog cms ディレクトリを移動 | |
// -------------------------- | |
if ($handle = opendir($ablogcmsDir)) { | |
while(false !== ($entry = readdir($handle))) { | |
if ($entry != "." && $entry != "..") { | |
rename($ablogcmsDir.$entry, $installPath ."/". $entry); | |
} | |
} | |
closedir($handle); | |
} else { | |
echo 'a-blog cms move Error ! :'.$ablogcmsDir; | |
exit; | |
} | |
// -------------------------- | |
// ioncube ファイルをダウンロード | |
// -------------------------- | |
$fp = fopen($downloadIoncube, "r"); | |
if ($fp !== FALSE) { | |
file_put_contents($zipFileIoncube, ""); | |
while(!feof($fp)) { | |
$buffer = fread($fp, 4096); | |
if ($buffer !== FALSE) { | |
file_put_contents($zipFileIoncube, $buffer, FILE_APPEND); | |
} | |
} | |
fclose($fp); | |
} else { | |
echo 'ioncube loader download Error ! : '.$download; | |
exit; | |
} | |
// -------------------------- | |
// ioncube Loader ファイルを解凍 | |
// -------------------------- | |
$zip = new ZipArchive(); | |
$res = $zip->open($zipFileIoncube); | |
if($res === true){ | |
$zip->extractTo($installPath); | |
$zip->close(); | |
} else { | |
echo 'ioncube loader unZip Error ! : '. $zipFileIoncube; | |
exit; | |
} | |
// -------------------------- | |
// ioncube Loader ファイルを移動 | |
// -------------------------- | |
$useIonCubeLoader = sprintf("ioncube_loader_dar_5.%d.so",$versionArray[1]); | |
rename("./ioncube/".$useIonCubeLoader, PHP_EXTENSION_DIR."/".$useIonCubeLoader); | |
// -------------------------- | |
// php.ini の設定 | |
// -------------------------- | |
# MAMP の php.ini のパスを設定する | |
$iniFile = "/Applications/MAMP/bin/php/php".phpversion()."/conf/php.ini"; | |
# 追記する設定内容 | |
$iniData = sprintf("\n\ndate.timezone = 'Asia/Tokyo'\n\nzend_extension = \"%s/ioncube_loader_dar_5.%d.so\"",PHP_EXTENSION_DIR ,$versionArray[1]); | |
$file = file_get_contents($iniFile); | |
if (preg_match("/ioncube_loader/i", $file)) { | |
# 設定済み | |
} else { | |
$file = fopen( $iniFile, "a+" ); | |
fwrite( $file, $iniData ); | |
fclose( $file ); | |
} | |
// -------------------------- | |
// .htaccess の設定 | |
// -------------------------- | |
rename("./htaccess.txt", './.htaccess'); | |
#rename("./archives/htaccess.txt", './archives/.htaccess'); | |
#rename("./archives_rev/htaccess.txt", './archives_rev/.htaccess'); | |
#rename("./private/htaccess.txt", './private/.htaccess'); | |
#rename("./media/htaccess.txt", './media/.htaccess'); | |
#rename("./theme/htaccess.txt", './theme/.htaccess'); | |
// -------------------------- | |
// DB 初期設定 | |
// -------------------------- | |
$data = sprintf("<?php | |
\$dbDefaultHost = '%s'; | |
\$dbDefaultName = '%s'; | |
\$dbDefaultCreate = '%s'; // '' or 'checked' | |
\$dbDefaultUser = '%s'; | |
\$dbDefaultPass = '%s'; | |
\$dbDefaultPrefix = 'acms_';",$dbHost,$dbName,$dbCreate,$dbUser,$dbPass); | |
$db_default = "./setup/lib/db_default.php"; | |
file_put_contents($db_default, $data); | |
// -------------------------- | |
// ファイルの削除 | |
// -------------------------- | |
unlink($zipFile); | |
unlink($zipFileIoncube); | |
unlink($phpName); | |
# index.html があった時にリネームしておく | |
if (is_file("./index.html")) { | |
rename("./index.html", "_index.html"); | |
} | |
# unlink($installPath."/ioncube/loader-wizard.php"); | |
dir_shori ("delete", "ioncube"); | |
# プログラム以外のディレクトリを削除 | |
dir_shori ("delete", $zipAfterDirName); | |
// -------------------------- | |
// インストーラーに飛ぶ | |
// -------------------------- | |
$jump = "http://".$_SERVER['HTTP_HOST'].str_replace($phpName, "", $_SERVER['SCRIPT_NAME']); | |
echo sprintf('<p style="text-align:center; margin-top:100px">MAMPを再起動して <a href="%s">%s</a> にアクセスしてください。</p>',$jump,$jump); | |
// -------------------------- | |
// ディレクトリを操作 function ( move / copy / delete ) | |
// -------------------------- | |
function dir_shori ($shori, $nowDir , $newDir="") { | |
if ($shori != "delete") { | |
if (!is_dir($newDir)) { | |
mkdir($newDir); | |
} | |
} | |
if (is_dir($nowDir)) { | |
if ($handle = opendir($nowDir)) { | |
while (($file = readdir($handle)) !== false) { | |
if ($file != "." && $file != "..") { | |
if ($shori == "copy") { | |
if (is_dir($nowDir."/".$file)) { | |
dir_shori("copy", $nowDir."/".$file, $newDir."/".$file); | |
} else { | |
copy($nowDir."/".$file, $newDir."/".$file); | |
} | |
} elseif ($shori == "move") { | |
rename($nowDir."/".$file, $newDir."/".$file); | |
} elseif ($shori == "delete") { | |
if (filetype($nowDir."/".$file) == "dir") { | |
dir_shori("delete", $nowDir."/".$file, ""); | |
} else { | |
unlink($nowDir."/".$file); | |
} | |
} | |
} | |
} | |
closedir($handle); | |
} | |
} | |
if ($shori == "move" || $shori == "delete") { | |
rmdir($nowDir); | |
} | |
return true; | |
} | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment