|
| 1 | +<?php |
| 2 | +//MODX BUILD ENVIRONMENT GUI v1 |
| 3 | + |
| 4 | +const MODX_CORE_PATH = MODX_BASE_PATH . 'core/'; |
| 5 | + |
| 6 | +if (!isset($_REQUEST['getpackage']) && empty($_REQUEST['getpackage'])) { |
| 7 | + |
| 8 | + $current_dir = dirname(__FILE__); |
| 9 | + |
| 10 | + $scanned_directory = array_diff(scandir($current_dir), array('..', '.')); |
| 11 | + echo "<h1>MODX build environment GUI</h1>"; |
| 12 | + echo "<b>Available packages for build:</b> (with versions from build.config.php if exists)<br/><br/>"; |
| 13 | + //echo "<b>Данные о версии берутся из файла конфигурации пакета</b> (build.config.php)<br/><br/>"; |
| 14 | + foreach ($scanned_directory as $packagename) { |
| 15 | + if (is_dir($current_dir.'/'.$packagename)) { |
| 16 | + $config = file_get_contents($current_dir.'/'.$packagename.'/'."build.config.php"); |
| 17 | + /*parse version*/ |
| 18 | + $version_preg = "#PKG_VERSION['\",=\s]*([0-9\.]+)#"; |
| 19 | + $release_preg = "#PKG_RELEASE['\",=\s]*([a-z0-9\.]+)['\"]#"; |
| 20 | + $version = ''; |
| 21 | + $matches = []; |
| 22 | + if (preg_match($version_preg, $config, $matches)) { |
| 23 | + $version .= $matches[1]; |
| 24 | + } |
| 25 | + if (preg_match($release_preg, $config, $matches)) { |
| 26 | + $version .= '-'.$matches[1]; |
| 27 | + } |
| 28 | + echo "<b>{$packagename}</b> <a target='_blank' href='/_build/{$packagename}/build.transport.php'>[build package]</a> (".$version.")<br/><br/>"; |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + //echo "<div style='color:#aaa; margin-top: 200px'>Made for MODX RSC by @dimasites and friends</div>"; |
| 33 | + |
| 34 | +}else{ |
| 35 | +// Define paths |
| 36 | + if (isset($_SERVER['MODX_BASE_PATH'])) { |
| 37 | + define('MODX_BASE_PATH', $_SERVER['MODX_BASE_PATH']); |
| 38 | + } elseif (file_exists(dirname(__FILE__, 2) . '/core')) { |
| 39 | + define('MODX_BASE_PATH', dirname(__FILE__, 2) . '/'); |
| 40 | + } else { |
| 41 | + define('MODX_BASE_PATH', dirname(__FILE__, 3) . '/'); |
| 42 | + } |
| 43 | + |
| 44 | + $file = MODX_CORE_PATH.'packages/'.$_REQUEST['getpackage'].'.transport.zip'; |
| 45 | + if (file_exists($file)) { |
| 46 | + header('Content-Description: File Transfer'); |
| 47 | + header('Content-Type: application/octet-stream'); |
| 48 | + header('Content-Disposition: attachment; filename="' . basename($file) . '"'); |
| 49 | + header('Expires: 0'); |
| 50 | + header('Cache-Control: must-revalidate'); |
| 51 | + header('Pragma: public'); |
| 52 | + header('Content-Length: ' . filesize($file)); |
| 53 | + readfile($file); |
| 54 | + exit; |
| 55 | + } |
| 56 | +} |
0 commit comments