Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 19 additions & 62 deletions bin/.jshintrc
Original file line number Diff line number Diff line change
@@ -1,63 +1,20 @@
// --------------------------------------------------------------------
// WordPress JSHint Configuration
// --------------------------------------------------------------------
{
"bitwise" : true, // Prohibit bitwise operators (&, |, ^, etc.).
"curly" : true, // Require {} for every new block or scope.
"eqeqeq" : true, // Require triple equals i.e. `===`.
"forin" : true, // Tolerate `for in` loops without `hasOwnPrototype`.
"immed" : true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
"latedef" : true, // Prohibit variable use before definition.
"newcap" : true, // Require capitalization of all constructor functions e.g. `new F()`.
"noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`.
"noempty" : true, // Prohibit use of empty blocks.
"nonew" : true, // Prohibit use of constructors for side-effects.
"plusplus" : false, // Prohibit use of `++` & `--`.
"regexp" : false, // Prohibit `.` and `[^...]` in regular expressions.
"undef" : true, // Require all non-global variables be declared before they are used.
"strict" : true, // Require `use strict` pragma in every file.
"trailing" : true, // Prohibit trailing whitespaces.
"asi" : false, // Tolerate Automatic Semicolon Insertion (no semicolons).
"boss" : false, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments.
"debug" : false, // Allow debugger statements e.g. browser breakpoints.
"eqnull" : false, // Tolerate use of `== null`.
"es5" : false, // Allow EcmaScript 5 syntax.
"esnext" : false, // Allow ES.next specific features such as `const` and `let`.
"evil" : false, // Tolerate use of `eval`.
"expr" : false, // Tolerate `ExpressionStatement` as Programs.
"funcscope" : false, // Tolerate declarations of variables inside of control structures while accessing them later from the outside.
"globalstrict" : false, // Allow global "use strict" (also enables 'strict').
"iterator" : false, // Allow usage of __iterator__ property.
"lastsemic" : false, // Tolerate missing semicolons when it is omitted for the last statement in a one-line block.
"laxbreak" : false, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons.
"laxcomma" : false, // Suppress warnings about comma-first coding style.
"loopfunc" : false, // Allow functions to be defined within loops.
"multistr" : false, // Tolerate multi-line strings.
"onecase" : false, // Tolerate switches with just one case.
"proto" : false, // Tolerate __proto__ property. This property is deprecated.
"regexdash" : false, // Tolerate unescaped last dash i.e. `[-...]`.
"scripturl" : false, // Tolerate script-targeted URLs.
"smarttabs" : false, // Tolerate mixed tabs and spaces when the latter are used for alignmnent only.
"shadow" : false, // Allows re-define variables later in code e.g. `var x=1; x=2;`.
"sub" : false, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
"supernew" : true, // Tolerate `new function () { ... };` and `new Object;`.
"validthis" : false, // Tolerate strict violations when the code is running in strict mode and you use this in a non-constructor function.
"browser" : true, // Standard browser globals e.g. `window`, `document`.
"couch" : false, // Enable globals exposed by CouchDB.
"devel" : false, // Allow development statements e.g. `console.log();`.
"dojo" : false, // Enable globals exposed by Dojo Toolkit.
"jquery" : true, // Enable globals exposed by jQuery JavaScript library.
"mootools" : false, // Enable globals exposed by MooTools JavaScript framework.
"node" : false, // Enable globals available when code is running inside of the NodeJS runtime environment.
"nonstandard" : false, // Define non-standard but widely adopted globals such as escape and unescape.
"prototypejs" : false, // Enable globals exposed by Prototype JavaScript framework.
"rhino" : false, // Enable globals available when your code is running inside of the Rhino runtime environment.
"wsh" : false, // Enable globals available when your code is running as a script for the Windows Script Host.
"nomen" : false, // Prohibit use of initial or trailing underbars in names.
"onevar" : false, // Allow only one `var` statement per function.
"passfail" : false, // Stop on first error.
"white" : false, // Check against strict whitespace and indentation rules.
"maxerr" : 100, // Maximum errors before stopping.
"predef" : [], // Extra globals.
"indent" : 4 // Specify indentation spacing
}
"boss": true,
"curly": true,
"eqeqeq": true,
"eqnull": true,
"expr": true,
"immed": true,
"noarg": true,
"quotmark": "single",
"trailing": true,
"undef": true,
"unused": true,

"browser": true,

"globals": {
"jQuery": false,
"wp": false
}
}
4 changes: 2 additions & 2 deletions bin/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ node_js:
env:
- WP_VERSION=master WP_MULTISITE=0
- WP_VERSION=master WP_MULTISITE=1
- WP_VERSION=3.7 WP_MULTISITE=0
- WP_VERSION=3.7 WP_MULTISITE=1
- WP_VERSION=latest WP_MULTISITE=0
- WP_VERSION=latest WP_MULTISITE=1

before_script:
- export WP_TESTS_DIR=/tmp/wordpress-tests/
Expand Down
14 changes: 13 additions & 1 deletion bin/class-wordpress-readme-parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,20 @@ function __construct( $args = array() ) {
*/
function to_markdown( $params = array() ) {

$general_section_formatter = function ( $body ) use ( $params ) {
$body = preg_replace(
'#\[youtube\s+(?:http://www\.youtube\.com/watch\?v=|http://youtu\.be/)(.+?)\]#',
'[![Play video on YouTube](http://i1.ytimg.com/vi/$1/hqdefault.jpg)](http://www.youtube.com/watch?v=$1)',
$body
);
return $body;
};

// Parse sections
$section_formatters = array(
'Description' => function ( $body ) use ( $params ) {
if ( isset( $params['travis_ci_url'] ) ) {
$body .= sprintf( "\n\n[![Build Status](%s.png)](%s)", $params['travis_ci_url'], $params['travis_ci_url'] );
$body .= sprintf( "\n\n[![Build Status](%s.png?branch=master)](%s)", $params['travis_ci_url'], $params['travis_ci_url'] );
}
return $body;
},
Expand Down Expand Up @@ -170,9 +179,12 @@ function ( $tag ) {
$markdown .= "\n";

$body = $section['body'];

$body = call_user_func( $general_section_formatter, $body );
if ( isset( $section_formatters[$section['heading']] ) ) {
$body = trim( call_user_func( $section_formatters[$section['heading']], $body ) );
}

if ( $body ) {
$markdown .= sprintf( "%s\n", $body );
}
Expand Down
9 changes: 8 additions & 1 deletion bin/install-wp-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ set -ex
# set up a WP install
WP_CORE_DIR=/tmp/wordpress/
mkdir -p $WP_CORE_DIR
wget -nv -O /tmp/wordpress.tar.gz https://github.com/WordPress/WordPress/tarball/$WP_VERSION

if [ $WP_VERSION == 'latest' ]; then
ARCHIVE_URL='http://wordpress.org/latest.tar.gz'
else
ARCHIVE_URL="https://github.com/WordPress/WordPress/tarball/$WP_VERSION"
fi

wget -nv -O /tmp/wordpress.tar.gz $ARCHIVE_URL
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR

# set up testing suite
Expand Down
27 changes: 27 additions & 0 deletions bin/phpcs.ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards for Plugins">
<description>Generally-applicable sniffs for WordPress plugins</description>

<rule ref="WordPress">
<exclude name="WordPress.VIP.RestrictedFunctions"/>
<exclude name="WordPress.VIP.SuperGlobalInputUsage"/>
<exclude name="WordPress.VIP.ValidatedSanitizedInput"/>
</rule>
<rule ref="WordPress.NamingConventions.ValidFunctionName">
<exclude-pattern>/tests/*</exclude-pattern><!-- because of PHPUnit method names -->
</rule>

<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"/>
<rule ref="Generic.PHP.DisallowShortOpenTag"/>
<rule ref="Generic.Files.ByteOrderMark"/>
<rule ref="Generic.PHP.LowerCaseConstant"/>
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>
<rule ref="Generic.PHP.NoSilencedErrors" />
<rule ref="Generic.ControlStructures.InlineControlStructure" />
<rule ref="Generic.Files.LineEndings">
<properties>
<property name="eolChar" value="\n"/>
</properties>
</rule>

</ruleset>
3 changes: 2 additions & 1 deletion bin/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ git subtree push --prefix bin \
git@github.com:x-team/wp-plugin-dev-lib.git master
```

Symlink to the `.travis.yml` and `.jshintrc` inside of the `bin/` directory you added:
Symlink to the `.travis.yml`, `.jshintrc`, and `phpcs.ruleset.xml` inside of the `bin/` directory you added:

```bash
ln -s bin/.travis.yml . && git add .travis.yml
ln -s bin/.jshintrc . && git add .jshintrc
ln -s bin/phpcs.ruleset.xml . && git add phpcs.ruleset.xml
```

Symlink to `pre-commit` from your project's `.git/hooks/pre-commit`:
Expand Down
4 changes: 2 additions & 2 deletions bin/svn-push
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
# Given a svn-url file one directory up, export the latest git commits to the specified SVN repo.
# Create a git release tag from the verison specified in the plugin file.
# Create a git release tag from the version specified in the plugin file.
# Author: Weston Ruter (@westonruter)

set -e
Expand Down Expand Up @@ -154,4 +154,4 @@ rm $svn_commit_file
# Restore branch
if [ $current_branch != 'master' ]; then
git checkout $current_branch
fi
fi
25 changes: 14 additions & 11 deletions dependency-minification.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: Dependency Minification
* Description: Concatenates and minifies scripts and stylesheets. Please install and activate <a href="http://scribu.net" target="_blank">scribu</a>'s <a href="http://wordpress.org/plugins/proper-network-activation/" target="_blank">Proper Network Activation</a> plugin <em>before</em> activating this plugin <em>network-wide</em>.
* Version: 0.9.7
* Version: 0.9.8
* Author: X-Team
* Author URI: http://x-team.com/wordpress/
* Text Domain: dependency-minification
Expand Down Expand Up @@ -59,6 +59,7 @@ static function setup() {
'admin_page_capability' => 'edit_theme_options',
'show_error_messages' => ( defined( 'WP_DEBUG' ) && WP_DEBUG ),
'disable_if_wp_debug' => true,
'print_manifest' => true,
),
self::$options
) );
Expand Down Expand Up @@ -398,7 +399,7 @@ static function admin_page() {
$_link_params = $link_params;
$_link_params['depmin_task'] = 'purge';
?>
<a class="submitdelete" title="<?php esc_attr_e( 'Delete the cached error to try again.', 'depmin' ) ?>" href="<?php echo esc_url( add_query_arg( $_link_params, admin_url( 'admin-ajax.php' ) ) ) ?>">
<a class="submitdelete" title="<?php esc_attr_e( 'Delete the cached error to try again.', 'depmin' ) ?>" href="<?php echo esc_url( admin_url( 'admin-ajax.php' ) . '?' . http_build_query( $_link_params ) ) ?>">
<?php esc_html_e( 'Try again', 'dependency-minification' ) ?>
</a>
</span>
Expand All @@ -413,14 +414,14 @@ static function admin_page() {
$_link_params = $link_params;
$_link_params['depmin_task'] = 'expire';
?>
<a href="<?php echo esc_url( add_query_arg( $_link_params, admin_url( 'admin-ajax.php' ) ) ) ?>" title="<?php esc_attr_e( 'Expire this item to gracefully regenerate', 'dependency-minification' ) ?>"><?php esc_html_e( 'Expire', 'dependency-minification' ) ?></a> |
<a href="<?php echo esc_url( admin_url( 'admin-ajax.php' ) . '?' . http_build_query( $_link_params ) ) ?>" title="<?php esc_attr_e( 'Expire this item to gracefully regenerate', 'dependency-minification' ) ?>"><?php esc_html_e( 'Expire', 'dependency-minification' ) ?></a> |
</span>
<span class="trash">
<?php
$_link_params = $link_params;
$_link_params['depmin_task'] = 'purge';
?>
<a class="submitdelete" title="<?php esc_attr_e( 'Purge item from cache (delete immediately; NOT recommended)', 'dependency-minification' ) ?>" href="<?php echo esc_url( add_query_arg( $_link_params, admin_url( 'admin-ajax.php' ) ) ) ?>"><?php esc_html_e( 'Purge', 'dependency-minification' ) ?></a> |
<a class="submitdelete" title="<?php esc_attr_e( 'Purge item from cache (delete immediately; NOT recommended)', 'dependency-minification' ) ?>" href="<?php echo esc_url( admin_url( 'admin-ajax.php' ) . '?' . http_build_query( $_link_params ) ) ?>"><?php esc_html_e( 'Purge', 'dependency-minification' ) ?></a> |
</span>
<span class="view">
<a href="<?php echo esc_url( $minified_src ) ?>" target="_blank" title="<?php esc_attr_e( 'View minified dependencies (opens in new window)', 'dependency-minification' ) ?>" rel="permalink"><?php esc_html_e( 'View minified', 'dependency-minification' ) ?></a>
Expand All @@ -431,7 +432,7 @@ static function admin_page() {
$_link_params = $link_params;
$_link_params['depmin_task'] = 'purge';
?>
<a class="submitdelete" title="<?php esc_attr_e( 'Delete the cached error to try again.', 'dependency-minification' ) ?>" href="<?php echo esc_url( add_query_arg( $_link_params, admin_url( 'admin-ajax.php' ) ) ) ?>"><?php esc_html_e( 'Try again', 'dependency-minification' ) ?></a>
<a class="submitdelete" title="<?php esc_attr_e( 'Delete the cached error to try again.', 'dependency-minification' ) ?>" href="<?php echo esc_url( admin_url( 'admin-ajax.php' ) . '?' . http_build_query( $_link_params ) ) ?>"><?php esc_html_e( 'Try again', 'dependency-minification' ) ?></a>
</span>
<?php endif; ?>
</div>
Expand Down Expand Up @@ -866,13 +867,15 @@ static function minify( $cached ) {
$contents = '';

// Print a manifest of the dependencies
$contents .= sprintf("/*! This minified dependency bundle includes:\n");
$i = 0;
foreach ( $srcs as $src ) {
$i += 1;
$contents .= sprintf( " * %02d. %s\n", $i, $src );
if ( self::$options['print_manifest'] ) {
$contents .= sprintf("/*! This minified dependency bundle includes:\n");
$i = 0;
foreach ( $srcs as $src ) {
$i += 1;
$contents .= sprintf( " * %02d. %s\n", $i, $src );
}
$contents .= sprintf(" */\n\n");
}
$contents .= sprintf(" */\n\n");

// Minify
// Note: semicolon needed in case a file lacks trailing semicolon
Expand Down
14 changes: 11 additions & 3 deletions minify/JS/ClosureCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
* @todo can use a stream wrapper to unit test this?
*/
class Minify_JS_ClosureCompiler {
const URL = 'http://closure-compiler.appspot.com/compile';
/**
* @var $url URL to compiler server. defaults to google server
*/
protected $url = 'http://closure-compiler.appspot.com/compile';

/**
* Minify Javascript code via HTTP request to the Closure Compiler API
Expand All @@ -34,12 +37,17 @@ public static function minify($js, array $options = array())
* @param array $options
*
* fallbackFunc : default array($this, 'fallback');
* compilerUrl : URL to closure compiler server
*/
public function __construct(array $options = array())
{
$this->_fallbackFunc = isset($options['fallbackMinifier'])
? $options['fallbackMinifier']
: array($this, '_fallback');

if (isset($options['compilerUrl'])) {
$this->url = $options['compilerUrl'];
}
}

public function min($js)
Expand Down Expand Up @@ -76,7 +84,7 @@ protected function _getResponse($postBody)
{
$allowUrlFopen = preg_match('/1|yes|on|true/i', ini_get('allow_url_fopen'));
if ($allowUrlFopen) {
$contents = file_get_contents(self::URL, false, stream_context_create(array(
$contents = file_get_contents($this->url, false, stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => "Content-type: application/x-www-form-urlencoded\r\nConnection: close\r\n",
Expand All @@ -86,7 +94,7 @@ protected function _getResponse($postBody)
)
)));
} elseif (defined('CURLOPT_POST')) {
$ch = curl_init(self::URL);
$ch = curl_init($this->url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded'));
Expand Down
40 changes: 26 additions & 14 deletions minify/JS/JSMin.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,9 @@ protected function action($command)
break;
}
if ($this->isEOF($this->a)) {
$byte = $this->inputIndex - 1;
throw new JSMin_UnterminatedStringException(
"JSMin: Unterminated String at byte {$this->inputIndex}: {$str}");
"JSMin: Unterminated String at byte {$byte}: {$str}");
}
$str .= $this->a;
if ($this->a === '\\') {
Expand Down Expand Up @@ -251,8 +252,9 @@ protected function action($command)
$this->a = $this->get();
$pattern .= $this->a;
} elseif ($this->isEOF($this->a)) {
$byte = $this->inputIndex - 1;
throw new JSMin_UnterminatedRegExpException(
"JSMin: Unterminated RegExp at byte {$this->inputIndex}: {$pattern}");
"JSMin: Unterminated RegExp at byte {$byte}: {$pattern}");
}
$this->output .= $this->a;
$this->lastByteOut = $this->a;
Expand All @@ -272,23 +274,33 @@ protected function isRegexpLiteral()
// we obviously aren't dividing
return true;
}
if ($this->a === ' ' || $this->a === "\n") {
$length = strlen($this->output);
if ($length < 2) { // weird edge case
return true;

// we have to check for a preceding keyword, and we don't need to pattern
// match over the whole output.
$recentOutput = substr($this->output, -10);

// check if return/typeof directly precede a pattern without a space
foreach (array('return', 'typeof') as $keyword) {
if ($this->a !== substr($keyword, -1)) {
// certainly wasn't keyword
continue;
}
// you can't divide a keyword
if (preg_match('/(?:case|else|in|return|typeof)$/', $this->output, $m)) {
if ($this->output === $m[0]) { // odd but could happen
return true;
}
// make sure it's a keyword, not end of an identifier
$charBeforeKeyword = substr($this->output, $length - strlen($m[0]) - 1, 1);
if (! $this->isAlphaNum($charBeforeKeyword)) {
if (preg_match("~(^|[\\s\\S])" . substr($keyword, 0, -1) . "$~", $recentOutput, $m)) {
if ($m[1] === '' || !$this->isAlphaNum($m[1])) {
return true;
}
}
}

// check all keywords
if ($this->a === ' ' || $this->a === "\n") {
if (preg_match('~(^|[\\s\\S])(?:case|else|in|return|typeof)$~', $recentOutput, $m)) {
if ($m[1] === '' || !$this->isAlphaNum($m[1])) {
return true;
}
}
}

return false;
}

Expand Down
Loading