-
-
Save machadoug/4089355 to your computer and use it in GitHub Desktop.
A script to strip whitespace. Used as a EasyCreator BuildAction ™:PKeeps the first block comment from the file (if any)@todo Get package information from EasyCreator
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
#!/usr/bin/php | |
<?php | |
/** | |
* @package EasyCreator | |
* @subpackage Helpers.Scripts | |
* @author Nikolai Plath {@link https://github.com/elkuku} | |
* @author Created on 25-May-2012 | |
* @license GNU/GPL | |
* @copyright Get Copyright from EasyCreator | |
*/ | |
// We are a valid Joomla entry point. | |
// Set flag that this is a parent file. | |
const _JEXEC = 1; | |
// Increase error reporting to that any errors are displayed. | |
// Note, you would not use these settings in production. | |
error_reporting(- 1); | |
ini_set('display_errors', true); | |
// Bootstrap the application. | |
// Load system defines | |
if (file_exists(dirname(__DIR__) . '/defines.php')) | |
{ | |
require_once dirname(__DIR__) . '/defines.php'; | |
} | |
if (!defined('_JDEFINES')) | |
{ | |
define('JPATH_BASE', dirname(__DIR__)); | |
require_once JPATH_BASE . '/includes/defines.php'; | |
} | |
require_once JPATH_LIBRARIES . '/import.legacy.php'; | |
require_once JPATH_LIBRARIES . '/cms.php'; | |
// Load the configuration | |
require_once JPATH_CONFIGURATION . '/configuration.php'; | |
//-- @todo weird_dependency_error :P | |
defined('JPATH_SITE') || define('JPATH_SITE', 'X'); | |
defined('JPATH_BASE') || define('JPATH_BASE', 'X'); | |
/** | |
* An example command line application class. | |
* | |
* @package EasyCreator | |
* @subpackage Scripts | |
*/ | |
class EcrStripWhitespace extends JApplicationCli | |
{ | |
/** | |
* Execute the application. | |
* | |
* @throws Exception | |
* | |
* @return void | |
*/ | |
public function doExecute() | |
{ | |
$filesToIgnore = array('.svn', 'CVS', '.DS_Store', '__MACOSX'); | |
$filesToIgnore[]= 'browser.php'; | |
$filesToIgnore[]= 'safereval.class.php'; | |
$filesToIgnore[]= 'securimage.php'; | |
$filesToIgnore[]= 'play.php'; | |
$filesToIgnore[]= 'show.php'; | |
jimport('joomla.filesystem.folder'); | |
jimport('joomla.filesystem.file'); | |
$this->out() | |
->out('EasyCreator StripWhitespace') | |
->out('=======================') | |
->out(); | |
$dir = $this->input->get('dir', false, 'string'); | |
if( ! $dir) | |
throw new Exception('Please specify a base directory with \'dir\'', 5); | |
$files = JFolder::files($dir, '.php', true, true, $filesToIgnore); | |
$cnt = 0; | |
$comment = '<?php | |
/** | |
* @package GET PACKAGE NAME FROM EASYCREATOR | |
* @author GET AUTHOR NAME FROM EASYCREATOR {@link GET AUTHOR URL FROM EASYCREATOR} | |
* @author Created on '.date('d-M-Y').' | |
* @copyright GET COPYRIGHT FROM EASYCREATOR | |
* @license GET LICENSE FROM EASYCREATOR | |
*/ | |
'; | |
foreach($files as $file) | |
{ | |
$comment_matches = array(); | |
preg_match( "#/\*\*(.*?)\*/#s", file_get_contents($file), $comment_matches ); | |
if (isset($comment_matches[1])){ | |
$first_comment = "<?php\n/*".trim($comment_matches[1])."\n*/\n"; | |
// $first_comment = str_replace('ideal.fok.com.br', 'idealextensions.com', $first_comment); | |
// $first_comment = preg_replace("#@\b(copyright)\b(.*?)ideal(.*?)\n#si", '@copyright Copyright (C) 2006 - '.date('Y')." iDealExtensions.com. All rights reserved.\n",$first_comment); | |
}else{ | |
$first_comment = $comment; | |
} | |
$buffer = php_strip_whitespace($file); | |
if(substr($buffer, 0, 5) == '<?php'){ | |
$buffer= $first_comment.substr($buffer, 5); | |
} | |
JFile::write($file, $buffer); | |
$cnt ++; | |
} | |
$this->out(sprintf('%4d files total', $cnt)) | |
->out(); | |
return; | |
} | |
} | |
try | |
{ | |
JApplicationCli::getInstance('EcrStripWhitespace')->execute(); | |
} | |
catch(Exception $e) | |
{ | |
fwrite(STDOUT, $e->getMessage()."\n"); | |
$code = $e->getCode() ? : 1; | |
exit($code); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment