Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added mechanism to specify a constant for affiliate ID #483

Merged
merged 17 commits into from
May 2, 2014
Merged
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
5 changes: 5 additions & 0 deletions .ci-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export PHPCS_GITHUB_SRC=x-team/PHP_CodeSniffer
export PHPCS_GIT_TREE=subset-selection
export WPCS_GIT_TREE=rule-subset-with-phpcs-pr
export WPCS_STANDARD=WordPress:core-extra
export PHPCS_IGNORE='tests/*,includes/vendor/*'
21 changes: 13 additions & 8 deletions bin/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,29 @@ 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
- WP_VERSION=3.8 WP_MULTISITE=0
- WP_VERSION=3.8 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
- export PHPCS_DIR=/tmp/phpcs
- export PHPCS_GITHUB_SRC=squizlabs/PHP_CodeSniffer
- export PHPCS_GIT_TREE=master
- export WPCS_GITHUB_SRC=WordPress-Coding-Standards/WordPress-Coding-Standards
- export WPCS_GIT_TREE=master
- export WPCS_STANDARD=$(if [ -e phpcs.ruleset.xml ]; then echo phpcs.ruleset.xml; else echo WordPress; fi)
- if [ -e .ci-env.sh ]; then source .ci-env.sh; fi
- if [ -e phpunit.xml ] || [ -e phpunit.xml.dist ]; then wget -O /tmp/install-wp-tests.sh https://raw.githubusercontent.com/wp-cli/wp-cli/master/templates/install-wp-tests.sh; bash /tmp/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
- mkdir -p $PHPCS_DIR && curl -L https://github.com/$PHPCS_GITHUB_SRC/archive/$PHPCS_GIT_TREE.tar.gz | tar xvz --strip-components=1 -C $PHPCS_DIR
- mkdir -p $PHPCS_DIR/CodeSniffer/Standards/WordPress && curl -L https://github.com/$WPCS_GITHUB_SRC/archive/$WPCS_GIT_TREE.tar.gz | tar xvz --strip-components=1 -C $PHPCS_DIR/CodeSniffer/Standards/WordPress
- 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')
- $PHPCS_DIR/scripts/phpcs --standard=$WPCS_STANDARD $(if [ -n "$PHPCS_IGNORE" ]; then echo --ignore=$PHPCS_IGNORE; fi) $(find . -name '*.php')
- jshint .
6 changes: 3 additions & 3 deletions bin/class-wordpress-readme-parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function __construct( $args = array() ) {
throw new Exception( "Parse error in $metadatum" );
}
list( $name, $value ) = array_slice( $metadataum_matches, 1, 2 );
$this->metadata[$name] = $value;
$this->metadata[ $name ] = $value;
}
$this->metadata['Contributors'] = preg_split( '/\s*,\s*/', $this->metadata['Contributors'] );
$this->metadata['Tags'] = preg_split( '/\s*,\s*/', $this->metadata['Tags'] );
Expand Down Expand Up @@ -181,8 +181,8 @@ function ( $tag ) {
$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 ( isset( $section_formatters[ $section['heading'] ] ) ) {
$body = trim( call_user_func( $section_formatters[ $section['heading'] ], $body ) );
}

if ( $body ) {
Expand Down
65 changes: 0 additions & 65 deletions bin/install-wp-tests.sh

This file was deleted.

35 changes: 30 additions & 5 deletions bin/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

set -e

WPCS_STANDARD=$(if [ -e phpcs.ruleset.xml ]; then echo phpcs.ruleset.xml; else echo WordPress; fi)
if [ -e .ci-env.sh ]; then
source .ci-env.sh
fi

message="Checking staged changes..."
git_status_egrep='^[MARC].+'

Expand Down Expand Up @@ -44,9 +49,30 @@ if [ ${#staged_php_files[@]} != 0 ]; then
# PHPUnit
if [ -e phpunit.xml ] || [ -e phpunit.xml.dist ]; then
echo "## phpunit"
if [ "$USER" != 'vagrant' ] && command -v vagrant >/dev/null 2>&1 && command -v vassh >/dev/null 2>&1; then
echo "Running phpunit in vagrant..."
vassh phpunit
if [ "$USER" != 'vagrant' ]; then

# Check if we're in VVV
plugin_dir=$(pwd)
while [ ! -e Vagrantfile ]; do
if [ $(pwd) == '/' ] || [ "$last_dir" == $(pwd) ]; then
break
fi
last_dir=$(pwd)
cd ..
done
if [ -e Vagrantfile ] && grep -q vvv Vagrantfile; then
vvv_root=$(pwd)
absolute_vvv_plugin_path=/srv${plugin_dir:${#vvv_root}}
fi
cd $plugin_dir

if [ ! -z "$absolute_vvv_plugin_path" ]; then
echo "Running phpunit in VVV"
vagrant ssh -c "cd $absolute_vvv_plugin_path && phpunit"
elif command -v vassh >/dev/null 2>&1; then
echo "Running phpunit in vagrant via vassh..."
vassh phpunit
fi
elif ! command -v phpunit >/dev/null 2>&1;then
echo "Skipping phpunit since not installed"
elif [ -z "$WP_TESTS_DIR" ]; then
Expand All @@ -59,8 +85,7 @@ if [ ${#staged_php_files[@]} != 0 ]; then
# PHP_CodeSniffer WordPress Coding Standards
echo "## phpcs"
if command -v phpcs >/dev/null 2>&1; then
phpcs_standard=$(if [ -e phpcs.ruleset.xml ]; then echo phpcs.ruleset.xml; else echo WordPress; fi)
phpcs -p -s -v --standard=$phpcs_standard "${staged_php_files[@]}"
phpcs -p -s -v --standard=$WPCS_STANDARD $(if [ -n "$PHPCS_IGNORE" ]; then echo --ignore=$PHPCS_IGNORE; fi) "${staged_php_files[@]}"
else
echo "Skipping phpcs since not installed"
fi
Expand Down
11 changes: 11 additions & 0 deletions bin/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ cd .git/hooks
ln -s ../../bin/pre-commit .
```

You may customize the behavior of the `.travis.yml` and `pre-commit` hook by
specifying a `.ci-env.sh` in the root of the repo, for example:

```bash
export PHPCS_GITHUB_SRC=x-team/PHP_CodeSniffer
export PHPCS_GIT_TREE=subset-selection
export WPCS_GIT_TREE=rule-subset-with-phpcs-pr
export WPCS_STANDARD=WordPress:core-extra
export PHPCS_IGNORE='tests/*,includes/vendor/*'
```

The library includes a WordPress README [parser](class-wordpress-readme-parser.php) and [converter](generate-markdown-readme) to Markdown,
so you don't have to manually keep your `readme.txt` on WordPress.org in sync with the `readme.md` you have on GitHub. The
converter will also automatically recognize the presence of projects with Travis CI and include the status image
Expand Down
6 changes: 4 additions & 2 deletions connectors/menus.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static function action_links( $links, $record ) {
$menu_ids = wp_list_pluck( $menus, 'term_id' );

if ( in_array( $record->object_id, $menu_ids ) ) {
$links[ __( 'Edit Menu', 'stream' ) ] = admin_url( 'nav-menus.php?action=edit&menu=' . $record->object_id );
$links[ __( 'Edit Menu', 'stream' ) ] = admin_url( 'nav-menus.php?action=edit&menu=' . $record->object_id ); // xss ok (@todo fix WPCS rule)
}
}

Expand Down Expand Up @@ -148,7 +148,9 @@ public static function callback_delete_nav_menu( $term, $tt_id, $deleted_term )
*/
public static function callback_update_option_theme_mods( $old, $new ) {
// Disable if we're switching themes
if ( did_action( 'after_switch_theme' ) ) return;
if ( did_action( 'after_switch_theme' ) ) {
return;
}

$key = 'nav_menu_locations';

Expand Down
2 changes: 1 addition & 1 deletion connectors/widgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static function action_links( $links, $record ) {
global $wp_registered_sidebars;

if ( array_key_exists( $sidebar, $wp_registered_sidebars ) ) {
$links[ __( 'Edit Widget Area', 'stream' ) ] = admin_url( 'widgets.php#' . $sidebar );
$links[ __( 'Edit Widget Area', 'stream' ) ] = admin_url( 'widgets.php#' . $sidebar ); // xss ok (@todo fix WPCS rule)
}
}

Expand Down
43 changes: 34 additions & 9 deletions includes/extensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
*
* @author Chris Olbekson <chris@x-team.com>
*/
/**
* By defining the WP_STREAM_AFFILIATE_ID constant, links on the Extensions page
* will be appended with the ID specified.
*
* More details on the Stream Premium affiliate program here:
* https://wp-stream.com/affiliates/
*
* Copy and paste the line below into your `wp-config.php` file, and change the "1" to be your affiliate ID:
*
* define( 'WP_STREAM_AFFILIATE_ID', 1 );
*/

class WP_Stream_Extensions {

Expand Down Expand Up @@ -33,17 +44,17 @@ class WP_Stream_Extensions {
/**
* @var string|null
*/
var $license_key = NULL;
var $license_key = null;

/**
* @var bool
*/
public static $instance = false;

public static function get_instance() {
if ( ! self::$instance )
if ( ! self::$instance ) {
self::$instance = new self();

}
return self::$instance;
}

Expand Down Expand Up @@ -100,6 +111,15 @@ function get_extension_api() {
return false;
}

/**
* Gets the affiliate reference portion of a URL if the affiliate ID constant is set.
*
* @return string A query string of the format '?ref=1', where 1 is the affiliate ID
*/
function get_affiliate() {
return ( defined( 'WP_STREAM_AFFILIATE_ID' ) && is_int( WP_STREAM_AFFILIATE_ID ) ) ? sprintf( '?ref=%d', absint( WP_STREAM_AFFILIATE_ID ) ) : null;
}

/**
* Filters the plugin install api
*
Expand All @@ -116,6 +136,9 @@ function filter_plugin_api_info( $false, $action, $args ) {
/** @internal The querying the api using the filter endpoint doesn't seem to work. For now I'm looping through all the extensions to get the api info for using WordPress install api */
$site = esc_url_raw( parse_url( get_option( 'siteurl' ), PHP_URL_HOST ) );
$license = get_site_option( WP_Stream_Updater::LICENSE_KEY );

$join_url = self::API_TRANSPORT . self::API_DOMAIN . '/join/' . $this->get_affiliate();

foreach ( $this->get_extension_data() as $extension ) {
if ( $extension->slug == $args->slug ) {
if ( $this->verify_membership() ) {
Expand All @@ -133,7 +156,7 @@ function filter_plugin_api_info( $false, $action, $args ) {

return $api;
} else {
$message = '<p>' . sprintf( __( 'You must connect to your %s account to install extensions.', 'stream' ), '<strong>' . esc_html__( 'Stream Premium', 'stream' ) . '</strong>' ) . '</p><p>' . esc_html__( "Don't have an account?", 'stream' ) . '</p><p><a href="https://wp-stream.com/join/" target="_blank" class="button">' . esc_html__( 'Join Stream Premium', 'stream' ) . '</a></p>';
$message = '<p>' . sprintf( __( 'You must connect to your %s account to install extensions.', 'stream' ), '<strong>' . esc_html__( 'Stream Premium', 'stream' ) . '</strong>' ) . '</p><p>' . esc_html__( "Don't have an account?", 'stream' ) . '</p><p><a href="' . esc_url( $join_url ) . '" target="_blank" class="button">' . esc_html__( 'Join Stream Premium', 'stream' ) . '</a></p>';
wp_die( $message, 'Stream Extension Installation', array( 'response' => 200, 'back_link' => true ) ); // xss ok
}
}
Expand Down Expand Up @@ -182,7 +205,7 @@ function get_plugin_paths() {
$plugin_paths = array();
foreach ( get_plugins() as $path => $data ) {
if ( isset( $data['TextDomain'] ) && ! empty( $data['TextDomain'] ) ) {
$plugin_paths[$data['TextDomain']] = $path;
$plugin_paths[ $data['TextDomain'] ] = $path;
}
}
return $plugin_paths;
Expand All @@ -196,6 +219,7 @@ function get_plugin_paths() {
* @return mixed
*/
function extensions_display_header( $extensions ) {
$join_url = self::API_TRANSPORT . self::API_DOMAIN . '/join/' . $this->get_affiliate();
?>
<h2><?php esc_html_e( 'Stream Extensions', 'stream' ) ?>
<span class="theme-count"><?php echo absint( count( $extensions ) ) ?></span>
Expand All @@ -210,7 +234,7 @@ function extensions_display_header( $extensions ) {
<?php if ( ! $this->verify_membership() ) : ?>
<p class="description">
<?php esc_html_e( "Connect your Stream Premium account and authorize this domain to install and receive automatic updates for premium extensions. Don't have an account?", 'stream' ) ?>
<a href="<?php echo esc_url( self::API_TRANSPORT . self::API_DOMAIN . '/join/' ) ?>" class="stream-premium-join"><?php esc_html_e( 'Join Stream Premium', 'stream' ) ?></a>
<a href="<?php echo esc_url( $join_url ) ?>" class="stream-premium-join"><?php esc_html_e( 'Join Stream Premium', 'stream' ) ?></a>
</p>
<?php else : ?>
<p class="description" style="color: green;">
Expand All @@ -229,12 +253,13 @@ function extensions_display_header( $extensions ) {
* @return void
*/
function extensions_display_body( $extensions ) {
$extensions_url = self::API_TRANSPORT . self::API_DOMAIN . '/#extensions' . $this->get_affiliate();
if ( empty( $extensions ) ) { ?>
<h2><?php _e( 'Stream Extensions', 'stream' ) ?></h2>
<p>
<em><?php esc_html_e( 'Sorry, there was a problem loading the list of extensions.', 'stream' ) ?></em></p>
<p>
<a class="button button-primary" href="<?php echo esc_url( self::API_TRANSPORT . self::API_DOMAIN . '/#extensions' ) ?>" target="_blank"><?php esc_html_e( 'Browse All Extensions', 'stream' ) ?></a>
<a class="button button-primary" href="<?php echo esc_url( $extensions_url ) ?>" target="_blank"><?php esc_html_e( 'Browse All Extensions', 'stream' ) ?></a>
</p>
<?php
return;
Expand Down Expand Up @@ -345,8 +370,8 @@ function prepare_extensions_for_js( $extensions ) {
'activate18n' => __( 'Activate', 'stream' ),
'active18n' => __( 'Active', 'stream' ),
'actions' => array(
'activate' => wp_nonce_url( add_query_arg( array( 'action' => 'activate', 'plugin' => $extension->post_meta->plugin_path[0], 'plugin_status' => 'all', 'paged' => '1' ), self_admin_url( 'plugins.php' ) ), 'activate-plugin_' . $extension->post_meta->plugin_path[0] ),
'install' => wp_nonce_url( add_query_arg( array( 'action' => 'install-plugin', 'plugin' => $extension->slug ), self_admin_url( 'update.php' ) ), 'install-plugin_' . $extension->slug ),
'activate' => wp_nonce_url( add_query_arg( array( 'action' => 'activate', 'plugin' => $extension->post_meta->plugin_path[0], 'plugin_status' => 'all', 'paged' => '1' ), self_admin_url( 'plugins.php' ) ), 'activate-plugin_' . $extension->post_meta->plugin_path[0] ), // xss ok (todo fix WPCS sniff)
'install' => wp_nonce_url( add_query_arg( array( 'action' => 'install-plugin', 'plugin' => $extension->slug ), self_admin_url( 'update.php' ) ), 'install-plugin_' . $extension->slug ), // xss ok (todo fix WPCS sniff)
'delete' => null,
),
);
Expand Down
4 changes: 2 additions & 2 deletions includes/feeds.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ public static function feed_template() {
$die_title = esc_html__( 'Access Denied', 'stream' );
$die_message = '<h1>' . $die_title .'</h1><p>' . esc_html__( 'You don\'t have permission to view this feed, please contact your site Administrator.', 'stream' ) . '</p>';

if ( ! isset( $_GET[self::FEED_QUERY_VAR] ) || empty( $_GET[self::FEED_QUERY_VAR] ) ) {
if ( ! isset( $_GET[ self::FEED_QUERY_VAR ] ) || empty( $_GET[ self::FEED_QUERY_VAR ] ) ) {
wp_die( $die_message, $die_title );
}

$args = array(
'meta_key' => self::USER_FEED_KEY,
'meta_value' => $_GET[self::FEED_QUERY_VAR],
'meta_value' => $_GET[ self::FEED_QUERY_VAR ],
'number' => 1,
);
$user = get_users( $args );
Expand Down
2 changes: 2 additions & 0 deletions includes/filter-input.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ public static function filter( $var, $filter = null, $options = array() ) {
}

public static function is_regex( $var ) {
// @codingStandardsIgnoreStart
$test = @preg_match( $var, '' );
// @codingStandardsIgnoreEnd

return $test !== false;
}
Expand Down
Loading