Exemple #1
0
 /**
  * Function called from {@link PHP_Beautifier::process()} to process the tokens.
  *
  * If the received token is one of the keys of {@link $aFilterTokenFunctions}
  * a function with the same name of the value of that key is called.
  * If the method doesn't exists, {@link __call()} is called, and return
  * {@link PHP_Beautifier_Filter::BYPASS}. PHP_Beautifier, now, call the next Filter is its list.
  * If the method exists, it can return true or {@link PHP_Beautifier_Filter::BYPASS}.
  * 
  * @param array $token Token to be handled
  *
  * @access public
  * @return bool true if the token is processed, false bypass to the next Filter
  * @see PHP_Beautifier::process()
  */
 public function handleToken($token)
 {
     $this->aToken = $token;
     if (!$this->bOn) {
         return false;
     }
     $sMethod = $sValue = false;
     if (array_key_exists($token[0], $this->aFilterTokenFunctions)) {
         $sMethod = $this->aFilterTokenFunctions[$token[0]];
         //$sValue = $token[1];
     } elseif ($this->oBeaut->getTokenFunction($token[0])) {
         $sMethod = $this->oBeaut->getTokenFunction($token[0]);
     }
     $sValue = $token[1];
     if ($sMethod) {
         PHP_Beautifier_Common::getLog()->log($this->getName() . "->" . $sMethod . "(" . trim($sValue) . ")", PEAR_LOG_DEBUG);
         // return false if PHP_Beautifier_Filter::BYPASS
         $result = $this->{$sMethod}($sValue) !== PHP_Beautifier_Filter::BYPASS;
         if ($result) {
             PHP_Beautifier_Common::getLog()->log($this->getName() . "->" . $sMethod . " done", PEAR_LOG_DEBUG);
         }
         return $result;
     } else {
         // WEIRD!!! -> Add the same received
         $this->oBeaut->add($token[1]);
         PHP_Beautifier_Common::getLog()->log("Add same received:" . trim($token[1]), PEAR_LOG_DEBUG);
         return true;
     }
     // never go here
     return false;
 }
 /**
  * Function called from {@link PHP_Beautifier::process()} to process the tokens.
  *
  * If the received token is one of the keys of {@link $aFilterTokenFunctions}
  * a function with the same name of the value of that key is called.
  * If the method doesn't exists, {@link __call()} is called, and return
  * {@link PHP_Beautifier_Filter::BYPASS}. PHP_Beautifier, now, call the next Filter is its list.
  * If the method exists, it can return true or {@link PHP_Beautifier_Filter::BYPASS}.
  * @param array token
  * @return bool true if the token is processed, false bypass to the next Filter
  * @see PHP_Beautifier::process()
  */
 public function handleToken($token)
 {
     $this->aToken = $token;
     if (!$this->bOn) {
         return false;
     }
     $sMethod = $sValue = false;
     if (array_key_exists($token[0], $this->aFilterTokenFunctions)) {
         $sMethod = $this->aFilterTokenFunctions[$token[0]];
         $sValue = $token[1];
     } elseif ($this->oBeaut->getTokenFunction($token[0])) {
         $sMethod = $this->oBeaut->getTokenFunction($token[0]);
     }
     $sValue = $token[1];
     if ($sMethod) {
         if ($this->oBeaut->iVerbose > 5) {
             echo $sMethod . ":" . trim($sValue) . "\n";
         }
         // return false if PHP_Beautifier_Filter::BYPASS
         return $this->{$sMethod}($sValue) !== PHP_Beautifier_Filter::BYPASS;
     } else {
         // WEIRD!!! -> Add the same received
         $this->oBeaut->add($token[1]);
         if ($this->oBeaut->iVerbose > 5) {
             echo trim($token) . "\n";
         }
         return true;
     }
     // never go here
     return false;
 }
 private function __write_php_file($lang, $file, $content)
 {
     $content = (string) $content;
     require_once 'PHP/Beautifier.php';
     $oBeautifier = new PHP_Beautifier();
     $oBeautifier->addFilter('ArrayNested');
     $oBeautifier->setIndentChar("\t");
     $oBeautifier->setIndentNumber(1);
     $oBeautifier->setNewLine("\n");
     $oBeautifier->setInputString($content);
     $oBeautifier->process();
     // required
     $content = $oBeautifier->get();
     $content = mb_convert_encoding((string) $content, 'UTF-8');
     $dir = APPPATH . "i18n/{$lang}/";
     if (!is_dir($dir)) {
         mkdir($dir, 0777, TRUE);
     }
     // Write the contents to the file
     $file = "{$dir}{$file}.php";
     if (file_exists($file)) {
         // Load old file and compare
         $old_contents = file_get_contents($file);
         // If array text is identical, don't change the file
         if (substr($old_contents, strpos($old_contents, '$lang')) == substr($content, strpos($content, '$lang'))) {
             echo ".. unchanged, skipping\n";
             return;
         }
     }
     file_put_contents($file, $content);
     //chmod($file, 0755);
 }
Exemple #4
0
#!/usr/bin/php
<?php 
require_once 'PHP/Beautifier.php';
// Create the instance
$oBeautifier = new PHP_Beautifier();
echo "Filter Directory: " . dirname(__FILE__) . '/beautifier_filters' . "\n";
$oBeautifier->addFilterDirectory(dirname(__FILE__) . '/beautifier_filters');
// Add a filter, without any parameter
$oBeautifier->addFilter('TTDefault');
// Set the indent char, number of chars to indent and newline char
$oBeautifier->setIndentChar(' ');
$oBeautifier->setIndentNumber(4);
$oBeautifier->setNewLine("\n");
// Define the input file
$oBeautifier->setInputFile($argv[1]);
// Define an output file.
//$oBeautifier->setOutputFile( $argv[1] .'.beautified.php');
$oBeautifier->setOutputFile($argv[1]);
// Process the file. DONT FORGET TO USE IT
$oBeautifier->process();
// Show the file (echo to screen)
//$oBeautifier->show();
// Save the file
$oBeautifier->save();
 private function __write_php_file($lang, $file, $content)
 {
     $content = (string) $content;
     require_once 'PHP/Beautifier.php';
     $oBeautifier = new PHP_Beautifier();
     $oBeautifier->addFilter('ArrayNested');
     $oBeautifier->setIndentChar("\t");
     $oBeautifier->setIndentNumber(1);
     $oBeautifier->setNewLine("\n");
     $oBeautifier->setInputString($content);
     $oBeautifier->process();
     // required
     $content = $oBeautifier->get();
     $content = mb_convert_encoding((string) $content, 'UTF-8');
     $dir = APPPATH . "i18n/{$lang}/";
     if (!is_dir($dir)) {
         mkdir($dir, 0777, TRUE);
     }
     // Write the contents to the file
     $file = "{$dir}{$file}.php";
     file_put_contents($file, $content);
     //chmod($file, 0755);
 }
 private function ___beautify___($ugly_source, $params = array())
 {
     require_once 'PHP/Beautifier.php';
     $oBeautifier = new PHP_Beautifier();
     $default_params = array_merge(array('indent_char' => ' ', 'indent_number' => 4, 'new_line' => PHP_EOL, 'style' => 'allman'), $params);
     // add some filters if not exist already
     $oBeautifier->addFilterDirectory(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Filter');
     // Add filters for array and code indentation style
     $oBeautifier->addFilter('ArrayNested');
     $oBeautifier->addFilter('IndentStyles', array('style' => $default_params['style']));
     // Set the indent char, number of chars to indent and newline char
     $oBeautifier->setIndentChar($default_params['indent_char']);
     $oBeautifier->setIndentNumber($default_params['indent_number']);
     $oBeautifier->setNewLine($default_params['new_line']);
     // Define the input file
     $oBeautifier->setInputString($ugly_source);
     // Process the file. DON'T FORGET TO USE IT
     $oBeautifier->process();
     // return beautiful source
     return $oBeautifier->get();
 }
Exemple #7
0
 public function beautifyString($str)
 {
     if ($this->beautify) {
         if (!@(include_once 'PHP/Beautifier.php')) {
             return $str;
         }
         $o_b = new \PHP_Beautifier();
         $o_b->setBeautify(true);
         $o_b->addFilter('ListClassFunction');
         $o_b->setIndentChar(' ');
         $o_b->setIndentNumber(2);
         $o_b->setNewLine("\n");
         $o_b->setInputString("<? {$str} ?>");
         $o_b->process();
         $res = $o_b->get();
         $res = preg_replace('/^\\<\\?\\s+/', '', $res);
         $res = preg_replace('/\\s+\\?\\>$/', '', $res);
         return $res;
     } else {
         return $str;
     }
 }
Exemple #8
0
    $data = $smarty->fetch('civicrm_acl.tpl');
    $filename = 'civicrm_acl';
    if ($locale != 'en_US') {
        $filename .= ".{$locale}";
    }
    $filename .= '.mysql';
    $fd = fopen($sqlCodePath . $filename, "w");
    fputs($fd, $data);
    fclose($fd);
}
echo "\ncivicrm_domain.version := {$db_version}\n\n";
$tsLocale = 'en_US';
$sample = $smarty->fetch('civicrm_sample.tpl');
$sample .= $smarty->fetch('civicrm_acl.tpl');
file_put_contents($sqlCodePath . 'civicrm_sample.mysql', $sample);
$beautifier = new PHP_Beautifier();
// create a instance
$beautifier->addFilter('ArrayNested');
$beautifier->addFilter('Pear');
// add one or more filters
$beautifier->addFilter('NewLines', array('after' => 'class, public, require, comment'));
// add one or more filters
$beautifier->setIndentChar(' ');
$beautifier->setIndentNumber(4);
$beautifier->setNewLine("\n");
foreach (array_keys($tables) as $name) {
    $smarty->clear_all_cache();
    echo "Generating {$name} as " . $tables[$name]['fileName'] . "\n";
    $smarty->clear_all_assign();
    $smarty->assign_by_ref('table', $tables[$name]);
    $php = $smarty->fetch('dao.tpl');
    $constructorcode .= "    \$directory = dirname(__FILE__).DIRECTORY_SEPARATOR;\n";
    $constructorcode .= "    foreach(\$options['classmap'] as \$key => \$value) if(file_exists('{\$directory}../structures/{\$value}.php')) include_once('{\$directory}../structures/{\$value}.php');\n";
    $constructorcode .= "    parent::__construct(\$wsdl, \$options);";
    $aliascode = <<<EOD
class_alias("{$serviceName}", "{$oldServiceName}");
?>

EOD;
    $file = str_replace($oldServiceName, $serviceName, $file);
    $file = str_replace("parent::__construct(\$wsdl, \$options);", $constructorcode, $file);
    $file = str_replace("?>", $aliascode, $file);
    file_put_contents($serviceFile, $file);
    rename($serviceFile, "splitteroutput/services/{$serviceName}.php");
    file_put_contents("splitteroutput/services/{$oldServiceName}.php", "<?php include_once(\"{$serviceName}.php\"); ?>\n");
}
foreach (glob("splitteroutput/*.php") as $structureFile) {
    rename($structureFile, "splitteroutput/structures/" . basename($structureFile));
}
include_once "PHP/Beautifier.php";
if (class_exists('PHP_Beautifier')) {
    $beautifier = new PHP_Beautifier();
    $beautifier->addFilter('ArrayNested');
    $beautifier->setIndentChar("\t");
    $beautifier->setIndentNumber(1);
    foreach (glob("splitteroutput/*/*.php") as $file) {
        $beautifier->setInputFile($file);
        $beautifier->setOutputFile($file);
        $beautifier->process();
        $beautifier->save();
    }
}
 * PHP version 5
 *
 * @category   Coda Plugins
 * @package    Pear PHP
 * @subpackage PHP_Beautifier
 * @author     Sofia Cardita <*****@*****.**> 
 *
 */
chdir('/Applications/MAMP/bin/php/php5.3.6/share/pear/');
error_reporting(E_ALL);
$path = 'PHP/Beautifier.php';
if (!file_exists($path)) {
    echo 'File not found: ' . $path . '. Pear must be in your path. If not 
            you need to set the correct path to Pear\'s Beautifier.php. ' . 'Included paths: ' . get_include_path() . '. Change it in this file: ' . __FILE__;
    die;
}
require $path;
$source = '';
while ($inp = fread(STDIN, 8192)) {
    $source .= $inp;
}
$oToken = new PHP_Beautifier();
$oToken->addFilter('Pear');
$oToken->addFilter('DocBlock');
$oToken->addFilter('ArrayNested');
$oToken->addFilter('EqualsAlign');
//add other filters here
$oToken->setInputString($source);
$oToken->process();
// required
echo $oToken->show();
Exemple #11
0
</HEAD>
<BODY>
<h1 id='header'>Demo for PHP_Beautifier</h1>
<FORM action="" method="POST">
Enter your code:
<TEXTAREA name='text' rows='10' style='width:100%'><?php 
if (isset($_POST['text'])) {
    echo htmlentities($_POST['text']);
}
?>
</TEXTAREA>
<input type='submit' value='Beautify!' />
<?php 
if (isset($_POST['text'])) {
    include 'PHP/Beautifier.php';
    $oBeautify = new PHP_Beautifier();
    $oBeautify->setInputString($_POST['text']);
    $oBeautify->process();
    ?>
<h2>Beautified text</h2>
<code>
<?php 
    highlight_string(preg_replace("/\r\n|\n|\r/", "\n", $oBeautify->get()));
    ?>
</code>
    <?php 
    if ($db = sqlite_open('../contadores', 0666, $sqliteerror)) {
        //sqlite_query($db, 'CREATE TABLE contadores (pagina varchar(255),numero int(11))');
        $result = sqlite_query($db, "select * from contadores where pagina='" . $_SERVER['PHP_SELF'] . "'");
        if (!($aRow = sqlite_fetch_array($result))) {
            sqlite_query($db, "INSERT INTO contadores (pagina,numero) VALUES ('" . $_SERVER['PHP_SELF'] . "',1)");
 /**
  * Beautifies PHP code with the PHP_Beautify library.
  * 
  * @since       1.2.0
  * @see         http://beautifyphp.sourceforge.net/docs/
  * @see         http://beautifyphp.sourceforge.net/docs/PHP_Beautifier/tutorial_PHP_Beautifier.howtouse.script.pkg.html
  */
 private function _getBeautifiedPHPCode($sCode)
 {
     // Create the instance
     $_oBeautifier = new PHP_Beautifier();
     // Set the indent char, number of chars to indent and newline char
     $_oBeautifier->setIndentChar(' ');
     $_oBeautifier->setIndentNumber(4);
     $_oBeautifier->setNewLine("\n");
     // Set the code
     $_oBeautifier->setInputString($sCode);
     // Process the file. DON'T FORGET TO USE IT
     $_oBeautifier->process();
     return $_oBeautifier->get();
 }
#!/usr/bin/env php
<?php

require 'PHP/Beautifier.php';
error_reporting(1);

$source = file_get_contents($argv[1]);
$oToken = new PHP_Beautifier();
$oToken->addFilter('Pear');
$oToken->addFilter('DocBlock');
$oToken->addFilter('ArrayNested');
$oToken->setInputString($source);
$oToken->process(); // required
$oToken->show();