Skip to content

Commit

Permalink
Merge branch 'master' into issue-1
Browse files Browse the repository at this point in the history
Conflicts:
	stream-notifications.php
  • Loading branch information
shadyvb committed Jan 27, 2014
2 parents f43a31e + cbe92d1 commit 886bb13
Show file tree
Hide file tree
Showing 21 changed files with 1,030 additions and 134 deletions.
1 change: 1 addition & 0 deletions .jshintrc
1 change: 1 addition & 0 deletions .travis.yml
20 changes: 20 additions & 0 deletions bin/.jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"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
}
}
33 changes: 33 additions & 0 deletions bin/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
language:
- php
- node_js

php:
- 5.3
- 5.4

node_js:
- 0.10

env:
- WP_VERSION=master WP_MULTISITE=0
- WP_VERSION=master WP_MULTISITE=1
- WP_VERSION=latest WP_MULTISITE=0
- WP_VERSION=latest WP_MULTISITE=1

before_script:
- export WP_TESTS_DIR=/tmp/wordpress-tests/
- export PLUGIN_DIR=$(pwd)
- export PLUGIN_SLUG=$(basename $(pwd) | sed 's/^wp-//')
- if [ -e phpunit.xml ] || [ -e phpunit.xml.dist ]; then bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION; cd /tmp/wordpress/wp-content/plugins; ln -s $PLUGIN_DIR $PLUGIN_SLUG; cd $PLUGIN_DIR; fi
- pear config-set auto_discover 1
- pear install PHP_CodeSniffer
- git clone git://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git $(pear config-get php_dir)/PHP/CodeSniffer/Standards/WordPress
- phpenv rehash
- npm install -g jshint

script:
- find . -path ./bin -prune -o \( -name '*.php' -o -name '*.inc' \) -exec php -lf {} \;
- if [ -e phpunit.xml ] || [ -e phpunit.xml.dist ]; then phpunit; fi
- phpcs --standard=$(if [ -e phpcs.ruleset.xml ]; then echo phpcs.ruleset.xml; else echo WordPress; fi) $(find . -name '*.php')
- jshint .
203 changes: 203 additions & 0 deletions bin/class-wordpress-readme-parser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
<?php
/**
* Lightweight WordPress readme.txt parser and converter to Markdown
* The WordPress-Plugin-Readme-Parser project is too heavy and has too many dependencies for what we need (we don't need conversion to HTML)
* @link https://github.com/markjaquith/WordPress-Plugin-Readme-Parser Alternative to WordPress-Plugin-Readme-Parser
* @version 1.1.1
* @author Weston Ruter <weston@x-team.com> (@westonruter)
* @copyright Copyright (c) 2013, X-Team <http://x-team.com/wordpress/>
* @license GPLv2+
*/

class WordPress_Readme_Parser {
public $path;
public $source;
public $title = '';
public $short_description = '';
public $metadata = array();
public $sections = array();

function __construct( $args = array() ) {
$args = array_merge( get_object_vars( $this ), $args );
foreach ( $args as $key => $value ) {
$this->$key = $value;
}

$this->source = file_get_contents( $this->path );
if ( ! $this->source ) {
throw new Exception( 'readme.txt was empty or unreadable' );
}

// Parse metadata
$syntax_ok = preg_match( '/^=== (.+?) ===\n(.+?)\n\n(.+?)\n(.+)/s', $this->source, $matches );
if ( ! $syntax_ok ) {
throw new Exception( 'Malformed metadata block' );
}
$this->title = $matches[1];
$this->short_description = $matches[3];
$readme_txt_rest = $matches[4];
$this->metadata = array_fill_keys( array( 'Contributors', 'Tags', 'Requires at least', 'Tested up to', 'Stable tag', 'License', 'License URI' ), null );
foreach ( explode( "\n", $matches[2] ) as $metadatum ) {
if ( ! preg_match( '/^(.+?):\s+(.+)$/', $metadatum, $metadataum_matches ) ) {
throw new Exception( "Parse error in $metadatum" );
}
list( $name, $value ) = array_slice( $metadataum_matches, 1, 2 );
$this->metadata[$name] = $value;
}
$this->metadata['Contributors'] = preg_split( '/\s*,\s*/', $this->metadata['Contributors'] );
$this->metadata['Tags'] = preg_split( '/\s*,\s*/', $this->metadata['Tags'] );

$syntax_ok = preg_match_all( '/(?:^|\n)== (.+?) ==\n(.+?)(?=\n== |$)/s', $readme_txt_rest, $section_matches, PREG_SET_ORDER );
if ( ! $syntax_ok ) {
throw new Exception( 'Failed to parse sections from readme.txt' );
}
foreach ( $section_matches as $section_match ) {
array_shift( $section_match );

$heading = array_shift( $section_match );
$body = trim( array_shift( $section_match ) );
$subsections = array();

// @todo Parse out front matter /(.+?)(\n=\s+.+$)/s

// Parse subsections
if ( preg_match_all( '/(?:^|\n)= (.+?) =\n(.+?)(?=\n= |$)/s', $body, $subsection_matches, PREG_SET_ORDER ) ) {
$body = null;
foreach ( $subsection_matches as $subsection_match ) {
array_shift( $subsection_match );
$subsections[] = array(
'heading' => array_shift( $subsection_match ),
'body' => trim( array_shift( $subsection_match ) ),
);
}
}

$this->sections[] = compact( 'heading', 'body', 'subsections' );
}
}

/**
* Convert the parsed readme.txt into Markdown
* @param array|string [$params]
* @return string
*/
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?branch=master)](%s)", $params['travis_ci_url'], $params['travis_ci_url'] );
}
return $body;
},
'Screenshots' => function ( $body ) {
$body = trim( $body );
$new_body = '';
if ( ! preg_match_all( '/^\d+\. (.+?)$/m', $body, $screenshot_matches, PREG_SET_ORDER ) ) {
throw new Exception( 'Malformed screenshot section' );
}
foreach ( $screenshot_matches as $i => $screenshot_match ) {
$img_extensions = array( 'jpg', 'gif', 'png' );
foreach ( $img_extensions as $ext ) {
$filepath = sprintf( 'assets/screenshot-%d.%s', $i + 1, $ext );
if ( file_exists( dirname( $this->path ) . DIRECTORY_SEPARATOR . $filepath ) ) {
break;
}
else {
$filepath = null;
}
}
if ( empty( $filepath ) ) {
continue;
}

$screenshot_name = $screenshot_match[1];
$new_body .= sprintf( "### %s\n", $screenshot_name );
$new_body .= "\n";
$new_body .= sprintf( "![%s](%s)\n", $screenshot_name, $filepath );
$new_body .= "\n";
}
return $new_body;
},
);

// Format metadata
$formatted_metadata = $this->metadata;
$formatted_metadata['Contributors'] = join(
', ',
array_map(
function ( $contributor ) {
$contributor = strtolower( $contributor );
// @todo Map to GitHub account
return sprintf( '[%1$s](http://profiles.wordpress.org/%1$s)', $contributor );
},
$this->metadata['Contributors']
)
);
$formatted_metadata['Tags'] = join(
', ',
array_map(
function ( $tag ) {
return sprintf( '[%1$s](http://wordpress.org/plugins/tags/%1$s)', $tag );
},
$this->metadata['Tags']
)
);
$formatted_metadata['License'] = sprintf( '[%s](%s)', $formatted_metadata['License'], $formatted_metadata['License URI'] );
unset( $formatted_metadata['License URI'] );
if ( $this->metadata['Stable tag'] === 'trunk' ) {
$formatted_metadata['Stable tag'] .= ' (master)';
}

// Render metadata
$markdown = "<!-- DO NOT EDIT THIS FILE; it is auto-generated from readme.txt -->\n";
$markdown .= sprintf( "# %s\n", $this->title );
$markdown .= "\n";
if ( file_exists( 'assets/banner-1544x500.png' ) ) {
$markdown .= '![Banner](assets/banner-1544x500.png)';
$markdown .= "\n";
}
$markdown .= sprintf( "%s\n", $this->short_description );
$markdown .= "\n";
foreach ( $formatted_metadata as $name => $value ) {
$markdown .= sprintf( "**%s:** %s \n", $name, $value );
}
$markdown .= "\n";

foreach ( $this->sections as $section ) {
$markdown .= sprintf( "## %s ##\n", $section['heading'] );
$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 );
}
foreach ( $section['subsections'] as $subsection ) {
$markdown .= sprintf( "### %s ###\n", $subsection['heading'] );
$markdown .= sprintf( "%s\n", $subsection['body'] );
$markdown .= "\n";
}

$markdown .= "\n";
}

return $markdown;
}

}
3 changes: 3 additions & 0 deletions bin/contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Pull requests should be opened with the `develop` branch as the base. Do not
open pull requests into the `master` branch, as this branch contains the latest
stable release.
57 changes: 57 additions & 0 deletions bin/generate-markdown-readme
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env php
<?php
/**
* Look for WordPress readme in current directory or above and convert into markdown readme in same directory
* @version 1.0.1
* @author Weston Ruter <weston@x-team.com> (@westonruter)
* @copyright Copyright (c) 2013, X-Team <http://x-team.com/wordpress/>
* @license GPLv2+
*/

try {
if ( php_sapi_name() !== 'cli' ) {
throw new Exception( 'Only allowed in CLI mode.' );
}

$readme_txt_path = null;
while ( true ) {
foreach ( array( 'readme.txt', 'README.txt' ) as $readme_filename ) {
if ( file_exists( $readme_filename ) ) {
$readme_txt_path = realpath( $readme_filename );
break;
}
}

$old_cwd = getcwd();
if ( ! empty( $readme_txt_path ) || ! chdir( '..' ) || getcwd() === $old_cwd ) {
break;
}
}
if ( empty( $readme_txt_path ) ) {
throw new Exception( 'Failed to find a readme.txt or README.txt above the current working directory.' );
}

$readme_root = dirname( $readme_txt_path );
$readme_md_path = preg_replace( '/txt$/', 'md', $readme_txt_path );

require_once __DIR__ . '/class-wordpress-readme-parser.php';

$readme = new WordPress_Readme_Parser( array( 'path' => $readme_txt_path ) );

$md_args = array();
if ( file_exists( $readme_root . '/.travis.yml' ) ) {
$md_args['travis_ci_url'] = preg_replace( '/^.+?:(.+)\.git$/', 'https://travis-ci.org/$1', trim( `git config --get remote.origin.url` ) );
}
$markdown = $readme->to_markdown( $md_args );

$is_written = file_put_contents( $readme_md_path, $markdown );
if ( ! $is_written ) {
throw new Exception( sprintf( 'Failed to write to %s', $readme_md_path ) );
}
fwrite( STDERR, 'Successfully converted WordPress README to Markdown' . PHP_EOL );
fwrite( STDOUT, $readme_md_path . PHP_EOL );
}
catch( Exception $e ) {
fwrite( STDERR, $e->getMessage() . PHP_EOL );
exit( 1 );
}
65 changes: 65 additions & 0 deletions bin/install-wp-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash

if [ $# -lt 3 ]; then
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version]"
exit 1
fi

DB_NAME=$1
DB_USER=$2
DB_PASS=$3
DB_HOST=${4-localhost}
WP_VERSION=${5-master}

set -ex

# set up a WP install
WP_CORE_DIR=/tmp/wordpress/
mkdir -p $WP_CORE_DIR

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
svn co --ignore-externals --quiet http://unit-tests.svn.wordpress.org/trunk/ $WP_TESTS_DIR

# portable in-place argument for both GNU sed and Mac OSX sed
if [[ $(uname -s) == 'Darwin' ]]; then
ioption='-i ""'
else
ioption='-i'
fi

# generate testing config file
cd $WP_TESTS_DIR
cp wp-tests-config-sample.php wp-tests-config.php
sed $ioption "s:dirname( __FILE__ ) . '/wordpress/':'$WP_CORE_DIR':" wp-tests-config.php
sed $ioption "s/yourdbnamehere/$DB_NAME/" wp-tests-config.php
sed $ioption "s/yourusernamehere/$DB_USER/" wp-tests-config.php
sed $ioption "s/yourpasswordhere/$DB_PASS/" wp-tests-config.php
sed $ioption "s|localhost|${DB_HOST}|" wp-tests-config.php

# parse DB_HOST for port or socket references
PARTS=(${DB_HOST//\:/ })
DB_HOSTNAME=${PARTS[0]};
DB_SOCK_OR_PORT=${PARTS[1]};
EXTRA=""

if ! [ -z $DB_HOSTNAME ] ; then
if [[ "$DB_SOCK_OR_PORT" =~ ^[0-9]+$ ]] ; then
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
elif ! [ -z $DB_SOCK_OR_PORT ] ; then
EXTRA=" --socket=$DB_SOCK_OR_PORT"
elif ! [ -z $DB_HOSTNAME ] ; then
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
fi
fi

# create database
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
Loading

0 comments on commit 886bb13

Please sign in to comment.