<?php
    /* A stripped down 'bumpbot' to reproduce YUI Compressor warnings */
    /* Based on http://core.trac.wordpress.org/attachment/ticket/19592/bumpbot.php */


    /* Designed to run from inside a trunk directory, since we'll fix warnings and pass over again we don't want to up, cleanup, revert, or checkout; work with what we've got */
    /* `svn up` regularly */

    if ( 'cli' != php_sapi_name() ) exit( 'Nuh-uh...' );

    if ( !file_exists( 'wp-load.php' ) ) exit( 'Where is WordPress?' );

    /* Add some color to this black and white world */
    $warning = "\x1b[1;31m";
    $ok = "\x1b[1;32m";
    $normal = "\x1b[0m";

    $bin  = dirname( __FILE__ );
    $yui = $bin . '/yuicompressor-2.4.2.jar'; /* Get http://yuilibrary.com/download/yuicompressor/ */

    if ( !file_exists( $yui ) ) exit( 'Y U I?' );

    $yui = "java -jar $yui -v";

    $skip = 16 + 0; /* Useful for debugging particular files, there are 16 CSS files */
    $total = 0;
    foreach ( array('css', 'js') as $type ) {
        $files = explode( "\n", trim( `find . -name "*.dev.$type"` ) );
        
        $numfiles = sizeof( $files );
        $current = 0;

        foreach ( $files as $file ) {
            ++$current;
            if ( $total++ < $skip ) continue;
        
            $file = substr( $file, 0, -strlen( ".dev.$type" ) );
            $result = trim( `$yui --type $type -o $file.$type $file.dev.$type 2>&1` );
            
            if ( false === strpos( $result, '[WARNING]' ) )
                $result = "{$ok}OK{$normal}";
            else $result = $warning.strstr( $result, '[WARNING]' ).$normal;

            $noutof = "$current/$numfiles";
            $result = str_replace( "\n", "\n\t\t", $result );
            echo "$noutof: $file.dev.$type\n\t\t$result\n";
        }
    }

    echo "KTHNXBYE!\n";
?>
