Created
April 21, 2016 09:51
-
-
Save MekDrop/a173277a5d2cdbd751d69ff4e4a4fda7 to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
function xlog() { | |
$args = func_get_args(); | |
$line = $args[0]; | |
unset($args[0]); | |
$args = array_values($args); | |
if (empty($args)) { | |
echo $line; | |
} else { | |
vprintf($line, $args); | |
} | |
echo(PHP_EOL); | |
@ob_flush(); | |
@flush(); | |
} | |
function renameIfExist($bad_name, $good_name) { | |
if (!file_exists($bad_name)) return; | |
xlog("\tRenaming file '%s' to '%s'...", $bad_name, $good_name); | |
rename($bad_name, $good_name); | |
} | |
function loadNfo($nfoFile) { | |
global $modversion; | |
$modversion = []; | |
try { | |
if (file_exists('language/english/modinfo.php')) { | |
include_once 'language/english/modinfo.php'; | |
} | |
$contents = file_get_contents($nfoFile); | |
$contents = str_replace('require', 'include', $contents); | |
return $modversion; | |
} catch (Exception $ex) { | |
xlog("\t\tError: %s", $ex->getMessage()); | |
return null; | |
} | |
} | |
function createLicenseIfNotExist($nfoFile) { | |
if (!file_exists($nfoFile)) return; | |
if (file_exists('License.txt')) return; | |
xlog("\tGenerating license file from '%s'...", $nfoFile); | |
if (!($modversion = loadNfo($nfoFile))) return; | |
if (isset($modversion['license'])) { | |
xlog("\t\tLicense found: %s", $modversion['license']); | |
if (strstr($modversion['license'], 'LGPL') || strstr($modversion['license'], 'Lesser')) { | |
if (strstr($modversion['license'], 'v3')) { | |
$source = 'https://www.gnu.org/licenses/lgpl-3.0.txt'; | |
} elseif (strstr($modversion['license'], 'v2')) { | |
$source = 'https://www.gnu.org/licenses/lgpl-2.1.txt'; | |
} else { | |
$source = 'https://www.gnu.org/licenses/lgpl-2.1.txt'; | |
} | |
} elseif (strstr($modversion['license'], 'Affero')) { | |
$source = 'https://www.gnu.org/licenses/agpl-3.0.txt'; | |
} elseif (strstr($modversion['license'], 'GPL')) { | |
if (strstr($modversion['license'], 'v3')) { | |
$source = 'http://www.gnu.org/licenses/gpl-3.0.txt'; | |
} elseif (strstr($modversion['license'], 'v2')) { | |
$source = 'http://www.gnu.org/licenses/gpl-2.0.txt'; | |
} elseif (strstr($modversion['license'], 'v1')) { | |
$source = 'http://www.gnu.org/licenses/gpl-1.0.txt'; | |
} else { | |
$source = 'http://www.gnu.org/licenses/gpl-2.0.txt'; | |
} | |
} elseif (strstr($modversion['license'], 'MIT')) { | |
$source = 'https://soulsphere.org/hacks/bsd/license.rhtml?owner=' + $modversion['author'] + '&organisation=ImpressCMS&license=mit3&output=plaintext&columns=80'; | |
} else { | |
xlog("\t\tCan't find license source"); | |
return; | |
} | |
$content = file_get_contents($source); | |
if (isset($modversion['date'])) { | |
$modversion['date'] = date('Y', strtotime($modversion['date'])); | |
$content = str_replace('2016', $modversion['date'] . ', 2016', $content); | |
} | |
file_put_contents('License.txt', $content); | |
} else { | |
xlog("\t\tLicense information not found"); | |
} | |
} | |
function createReadmeIfNotExist($repo_name, $nfoFile) { | |
if (!file_exists($nfoFile)) return; | |
if (file_exists('README.md')) return; | |
if (file_exists('README.html')) return; | |
xlog("\tGenerating readme file from '%s'...", $nfoFile); | |
if (!($modversion = loadNfo($nfoFile))) return; | |
$content = '[![License](https://img.shields.io/github/license/ImpressCMS/'.$repo_name.'.svg?maxAge=2592000)](License.txt) | |
[![GitHub release](https://img.shields.io/github/release/ImpressCMS/'.$repo_name.'.svg?maxAge=2592000)](https://github.com/ImpressCMS/'.$repo_name.'/releases) | |
[![This is ImpressCMS module](https://img.shields.io/badge/ImpressCMS-module-F3AC03.svg?maxAge=2592000)](http://impresscms.org)' . PHP_EOL; | |
if (isset($modversion['name'])) { | |
$content .= '#' . $modversion['name'] . PHP_EOL; | |
} else { | |
$content .= '#' . $repo_name . PHP_EOL; | |
} | |
if (isset($modversion['description'])) { | |
$content .= $modversion['description'] . PHP_EOL; | |
} else { | |
$content .= 'This is module for [ImpressCMS](http://impresscms.org). Someday this description will be updated with some more usefull text'; | |
} | |
file_put_contents('README.md', $content); | |
} | |
define('ICMS_ROOT_PATH', __DIR__); | |
define('XOOPS_ROOT_PATH', __DIR__); | |
ini_set('max_execution_time', 0); | |
set_time_limit (0); | |
global $xoopsDB, $icmsDB, $icmsConfig; | |
$icmsConfig = []; | |
$xoopsDB = $icmsDB = new icms_db(); | |
function icms_getTablesArray(){} | |
function icms_getModuleHandler(){return icms::handler();} | |
function xoops_gethandler() {return icms::handler();} | |
function icms_loadLanguageFile(){} | |
function icms_getModuleInfo(){} | |
function icms_get_module_status(){} | |
class icms { | |
static $module; | |
static function handler() {return new icms_module_handler();} | |
} | |
class icms_module_handler { | |
public function getByDirname() {} | |
public function getGroupList() {} | |
public function getList() {} | |
} | |
class icms_db { | |
public function query() {} | |
public function prefix() {return '';} | |
public function fetchRow() {} | |
public function fetchArray() {} | |
} | |
class icms_db_criteria_Compo { | |
} | |
function smart_getEditors() {} | |
class_alias('icms_db_criteria_Compo', 'icms_db_criteria_Item'); | |
foreach (new DirectoryIterator (__DIR__) as $dir) { | |
if (!$dir->isDir()) continue; | |
$path = $dir->getFilename(); | |
if ($path == __DIR__) continue; | |
$repo_name = basename($path); | |
if ($repo_name{0} == '.') continue; | |
xlog("Processing %s repo...", $repo_name); | |
$pwd = getcwd(); | |
chdir($path); | |
renameIfExist('readme.txt', 'README.md'); | |
renameIfExist('README.txt', 'README.md'); | |
renameIfExist('readme.html', 'README.html'); | |
renameIfExist('README', 'README.md'); | |
renameIfExist('readme', 'README.md'); | |
renameIfExist('License', 'License.txt'); | |
renameIfExist('License.md', 'License.txt'); | |
renameIfExist('LICENSE.md', 'License.txt'); | |
createLicenseIfNotExist('icms_version.php'); | |
createLicenseIfNotExist('xoops_version.php'); | |
createReadmeIfNotExist($repo_name, 'icms_version.php'); | |
createReadmeIfNotExist($repo_name, 'xoops_version.php'); | |
shell_exec('git push'); | |
chdir($pwd); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment