コード例 #1
0
ファイル: i18n.php プロジェクト: rjmackay/kohana-i18n-manager
 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);
 }
コード例 #2
0
 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();
 }
コード例 #3
0
ファイル: beautifier.php プロジェクト: alachaum/timetrex
#!/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();
コード例 #4
0
ファイル: GenCode.php プロジェクト: ksecor/civicrm
$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');
    $beautifier->setInputString($php);
    if (empty($tables[$name]['base'])) {
        echo "No base defined for {$name}, skipping output generation\n";
        continue;
    }
    $directory = $phpCodePath . $tables[$name]['base'];
    createDir($directory);
    $beautifier->setOutputFile($directory . $tables[$name]['fileName']);
    $beautifier->process();
    // required
    $beautifier->save();
}
echo "Generating CRM_Core_I18n_SchemaStructure...\n";
$columns = array();
$indices = array();
foreach ($tables as $table) {
    if ($table['localizable']) {
        $columns[$table['name']] = array();
    } else {
        continue;
    }
    foreach ($table['fields'] as $field) {
        if ($field['localizable']) {
            $columns[$table['name']][$field['name']] = $field['sqlType'];
コード例 #5
0
 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);
 }
コード例 #6
0
ファイル: Generator.php プロジェクト: sebcode/proust
 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;
     }
 }
コード例 #7
0
 * 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();
コード例 #8
0
ファイル: index.php プロジェクト: rafasashi/PHP_Beautifier
<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)");
        } else {
            sqlite_query($db, "UPDATE  contadores SET numero=numero+1 where pagina='" . $_SERVER['PHP_SELF'] . "'");
コード例 #9
0
 /**
  * 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();
 }
コード例 #10
0
#!/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();