From 2d2a72a2759c6c4efc69435ea8f02190174163a0 Mon Sep 17 00:00:00 2001 From: Umesh Kumar Date: Mon, 10 Mar 2014 11:51:03 +0530 Subject: [PATCH] change repo --- .idea/.name | 1 + .idea/encodings.xml | 5 + .idea/gmail-inbox-action.iml | 9 ++ .idea/misc.xml | 5 + .idea/modules.xml | 9 ++ .idea/scopes/scope_settings.xml | 5 + .idea/vcs.xml | 7 + .idea/workspace.xml | 183 +++++++++++++++++++++++ .jshintrc | 1 + .travis.yml | 1 + README.md | 24 +++ app/GmailInboxAction.php | 177 ++++++++++++++++++++++ bin/.jshintrc | 20 +++ bin/.travis.yml | 33 +++++ bin/class-wordpress-readme-parser.php | 203 ++++++++++++++++++++++++++ bin/contributing.md | 3 + bin/generate-markdown-readme | 57 ++++++++ bin/install-wp-tests.sh | 65 +++++++++ bin/phpcs.ruleset.xml | 22 +++ bin/pre-commit | 74 ++++++++++ bin/readme.md | 54 +++++++ bin/svn-push | 157 ++++++++++++++++++++ index.php | 25 ++++ phpcs.ruleset.xml | 1 + readme.txt | 52 +++++++ 25 files changed, 1193 insertions(+) create mode 100644 .idea/.name create mode 100644 .idea/encodings.xml create mode 100644 .idea/gmail-inbox-action.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/scopes/scope_settings.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 120000 .jshintrc create mode 120000 .travis.yml create mode 100644 README.md create mode 100644 app/GmailInboxAction.php create mode 100644 bin/.jshintrc create mode 100644 bin/.travis.yml create mode 100644 bin/class-wordpress-readme-parser.php create mode 100644 bin/contributing.md create mode 100755 bin/generate-markdown-readme create mode 100755 bin/install-wp-tests.sh create mode 100644 bin/phpcs.ruleset.xml create mode 100755 bin/pre-commit create mode 100644 bin/readme.md create mode 100755 bin/svn-push create mode 100644 index.php create mode 120000 phpcs.ruleset.xml create mode 100644 readme.txt diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..b2e8cd8 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +gmail-inbox-action \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..e206d70 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/.idea/gmail-inbox-action.iml b/.idea/gmail-inbox-action.iml new file mode 100644 index 0000000..6b8184f --- /dev/null +++ b/.idea/gmail-inbox-action.iml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..1162f43 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..2381742 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml new file mode 100644 index 0000000..922003b --- /dev/null +++ b/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..c80f219 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..1af977b --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,183 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1394387100302 + 1394387100302 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.jshintrc b/.jshintrc new file mode 120000 index 0000000..e566925 --- /dev/null +++ b/.jshintrc @@ -0,0 +1 @@ +bin/.jshintrc \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 120000 index 0000000..948a887 --- /dev/null +++ b/.travis.yml @@ -0,0 +1 @@ +bin/.travis.yml \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..ab1839d --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +#Gmail Inbox Actions + +Allows to approve your wordpress comment from your Gmail inbox, without logging into your site. +## Requirements: + +- Emails must be [authenticated via DKIM or SPF](https://support.google.com/mail/answer/180707?hl=en) + - If you are unable to modify your DNS records to support this, one way of achieving is through the use of [Postmark] (https://postmarkapp.com) or Google Apps service +- Your domain of the DKIM or SPF signatures must match the domain of your From: email address exactly. eg for From: foo@bar.com the DKIM must be for the bar.com domain and not a subdomain such as email.bar.com. +- Emails must come from a static email address, eg foo@bar.com +- Emails must follow [Google's general email guidelines](https://support.google.com/mail/answer/81126?hl=en) + + +Once you have met these basic requirements, you can then [register with Google](https://developers.google.com/gmail/actions/registering-with-google) so your customers can start seeing the new Go-to Actions in their inboxes. + + +[Full list of requirements from Google](https://developers.google.com/gmail/actions/registering-with-google) + + +## Installation +Follows the normal installation, you can upload the gmail-inbox-action folder to `wp-content/plugins` folder + +## Configuration + +Update your Gmail account email in general settings. \ No newline at end of file diff --git a/app/GmailInboxAction.php b/app/GmailInboxAction.php new file mode 100644 index 0000000..cc600a2 --- /dev/null +++ b/app/GmailInboxAction.php @@ -0,0 +1,177 @@ +secret = ''; + add_action( 'wp_ajax_nopriv_gia_approve_comment', array( $this, 'gia_approve_comment' ) ); + add_action( 'wp_ajax_gia_approve_comment', array( $this, 'gia_approve_comment' ) ); + add_action( 'comment_post', array( $this, 'filter_mail_content_type' ) ); + } + + /** + * Calls generate_comment_secret and update_comment_secret for setting comment secret + * @param $comment_id + * + * @return string, If updated return string + */ + public function set_comment_secret( $comment_id ) { + //if empty comment id + if ( !$comment_id ) { + return; + } + //else generate comment secret + $comment_secret = $this->generate_comment_secret( $comment_id ); + //if comment secret, update comment meta + if ( $comment_secret ) { + $updated = $this->update_comment_secret( $comment_id, $comment_secret ); + } + + return $comment_secret; + } + + /** + * Generate comment secret for comment id + * @param $comment_id + * + * @return string, hash + */ + public function generate_comment_secret( $comment_id ) { + $static_num = 8; + $rand = rand( 1111, getrandmax() ); + $current_time = time(); + $str = $static_num * $comment_id . $current_time . $rand; + + return sha1( $str ); + } + + /** + * Stores comment secret in meta + * @param $comment_id + * @param $comment_secret + * + * @return mixed + */ + public function update_comment_secret( $comment_id, $comment_secret ) { + if ( !$comment_id || !$comment_secret ) { + return; + } + + return update_comment_meta( $comment_id, 'comment_secret', $comment_secret ); + } + + /** + * Verify comment secret + * @param $comment_id + * @param $comment_secret + * + * @return bool + */ + public function verify_comment_secret( $comment_id, $comment_secret ) { + if ( !$comment_id || !$comment_secret ) { + return; + } + $actual_comment_secret = get_comment_meta( $comment_id, 'comment_secret', true ); + if ( $actual_comment_secret === $comment_secret ) { + return true; + } + } + + /** + * Check comment secret and set header + */ + public function gia_approve_comment() { + if ( empty( $_REQUEST['id'] ) || empty( $_REQUEST['token'] ) ) { + header( 'HTTP/1.1 401 Unauthorized', true, 401 ); + die; + } + //uncomment when implementing + if ( !$_SERVER['REQUEST_METHOD'] == 'POST' || + !isset( $_SERVER['HTTP_USER_AGENT'] ) || + $_SERVER['HTTP_USER_AGENT'] != 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/1.0 (KHTML, like Gecko; Gmail Actions)' ) { + header( 'HTTP/1.1 401 Unauthorized', true, 401 ); + die; + } + //verify token + $verified = $this->verify_comment_secret( $_REQUEST['id'], $_REQUEST['token'] ); + if ( !$verified ) { + header( 'HTTP/1.1 401 Unauthorized', true, 401 ); + die; + } + //approve comment + $updated = wp_set_comment_status( $_REQUEST['id'], 'approve', FALSE ); + //if approved + if ( $updated ) { + header( 'HTTP/1.1 200 OK', true, 200 ); + die( 1 ); + } else { + header( 'HTTP/1.1 400 Bad Request', true, 400 ); + die; + } + } + + /** + * Filter notification mail to append gmail action schema + * @param $notify_message + * @param $comment_id + * + * @return string + */ + public function gia_modify_notification_text( $notify_message, $comment_id ) { + $message = ' + + '; + $message .= $notify_message; + $message .= ' + '; + return $message; + } + + /** + * Hooked on 'comment_post', actually calls set_comment_secret function + * @param $comment_id + */ + function filter_mail_content_type( $comment_id ) { + //update comment secret for gmail + $this->secret = $this->set_comment_secret( $comment_id ); + add_filter( 'comment_moderation_text', array( $this, 'gia_modify_notification_text' ), 1, 2 ); + add_filter( 'wp_mail_content_type', array( $this, 'set_html_content_type' ) ); + } + + /** + * Set mail content type + * @return string + */ + function set_html_content_type() { + return 'text/html'; + } + +} diff --git a/bin/.jshintrc b/bin/.jshintrc new file mode 100644 index 0000000..bf11264 --- /dev/null +++ b/bin/.jshintrc @@ -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 + } +} diff --git a/bin/.travis.yml b/bin/.travis.yml new file mode 100644 index 0000000..f1797e3 --- /dev/null +++ b/bin/.travis.yml @@ -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 . diff --git a/bin/class-wordpress-readme-parser.php b/bin/class-wordpress-readme-parser.php new file mode 100644 index 0000000..784b219 --- /dev/null +++ b/bin/class-wordpress-readme-parser.php @@ -0,0 +1,203 @@ + (@westonruter) + * @copyright Copyright (c) 2013, X-Team + * @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 = "\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; + } + +} diff --git a/bin/contributing.md b/bin/contributing.md new file mode 100644 index 0000000..8d23e4b --- /dev/null +++ b/bin/contributing.md @@ -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. diff --git a/bin/generate-markdown-readme b/bin/generate-markdown-readme new file mode 100755 index 0000000..d819a0e --- /dev/null +++ b/bin/generate-markdown-readme @@ -0,0 +1,57 @@ +#!/usr/bin/env php + (@westonruter) + * @copyright Copyright (c) 2013, X-Team + * @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 ); +} diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh new file mode 100755 index 0000000..464772b --- /dev/null +++ b/bin/install-wp-tests.sh @@ -0,0 +1,65 @@ +#!/usr/bin/env bash + +if [ $# -lt 3 ]; then + echo "usage: $0 [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 diff --git a/bin/phpcs.ruleset.xml b/bin/phpcs.ruleset.xml new file mode 100644 index 0000000..d6486e8 --- /dev/null +++ b/bin/phpcs.ruleset.xml @@ -0,0 +1,22 @@ + + + Generally-applicable sniffs for WordPress plugins + + + /tests/* + + + + + + + + + + + + + + + + diff --git a/bin/pre-commit b/bin/pre-commit new file mode 100755 index 0000000..8f50f0d --- /dev/null +++ b/bin/pre-commit @@ -0,0 +1,74 @@ +#!/bin/bash +# WordPress Plugin pre-commit hook + +set -e + +message="Checking staged changes..." +git_status_egrep='^[MARC].+' + +for i; do + case "$i" + in + -m) + message="Checking any uncommitted changes..." + git_status_egrep='^.?[MARC].+' + shift;; + esac +done + +echo $message + +# Check for staged JS files +IFS=$'\n' staged_js_files=( $(git status --porcelain | sed 's/[^ ]* -> *//g' | egrep $git_status_egrep'\.js$' | cut -c4-) ) +if [ ${#staged_js_files[@]} != 0 ]; then + # JSHint + if [ -e .jshintrc ]; then + echo "## jslint" + if command -v jshint >/dev/null 2>&1; then + jshint "${staged_js_files[@]}" + else + echo "Skipping jshint since not installed" + fi + fi + +fi + +# Check for staged PHP files +IFS=$'\n' staged_php_files=( $(git status --porcelain | sed 's/[^ ]* -> *//g' | egrep $git_status_egrep'\.php$' | cut -c4-) ) +if [ ${#staged_php_files[@]} != 0 ]; then + # PHP Syntax Check + for php_file in "${staged_php_files[@]}"; do + php -lf $php_file + done + + # 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 + elif ! command -v phpunit >/dev/null 2>&1;then + echo "Skipping phpunit since not installed" + elif [ -z "$WP_TESTS_DIR" ]; then + echo "Skipping phpunit since WP_TESTS_DIR env missing" + else + phpunit + fi + fi + + # 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[@]}" + else + echo "Skipping phpcs since not installed" + fi +fi + +# Make sure the readme.md never gets out of sync with the readme.txt +generate_markdown_readme=$(find . -name generate-markdown-readme -print -quit) +if [ -n "$generate_markdown_readme" ]; then + markdown_readme_path=$($generate_markdown_readme) + git add $markdown_readme_path +fi diff --git a/bin/readme.md b/bin/readme.md new file mode 100644 index 0000000..38c5812 --- /dev/null +++ b/bin/readme.md @@ -0,0 +1,54 @@ +wp-plugin-dev-lib +================= + +**Common code used during development of WordPress plugins** + +It is intended that this repo be included in plugin repo via git-subtree/submodule in a `bin/` directory. + +To **add** it to your repo, do: + +```bash +git subtree add --prefix bin \ + git@github.com:x-team/wp-plugin-dev-lib.git master --squash +``` + +To **update** the library with the latest changes: + +```bash +git subtree pull --prefix bin \ + git@github.com:x-team/wp-plugin-dev-lib.git master --squash +``` + +And if you have changes you want to **upstream**, do: + +```bash +git subtree push --prefix bin \ + git@github.com:x-team/wp-plugin-dev-lib.git master +``` + +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`: + +```bash +cd .git/hooks +ln -s ../../bin/pre-commit . +``` + +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 +in the markdown. Screenshots and banner images for WordPress.org are also automatically incorporated into the `readme.md`. + +What is also included in this repo is an [`svn-push`](svn-push) to push commits from a GitHub repo to the WordPress.org SVN repo for the plugin. +The `/assets/` directory in the root of the project will get automatically moved one directory above in the SVN repo (alongside +`trunk`, `branches`, and `tags`). To use, include an `svn-url` file in the root of your repo and let this file contains he full root URL +to the WordPress.org repo for plugin (don't include `trunk`). + +The utilities in this project were first developed to facilitate development of [X-Team](http://x-team.com/wordpress/)'s [plugins](http://profiles.wordpress.org/x-team/). diff --git a/bin/svn-push b/bin/svn-push new file mode 100755 index 0000000..c573756 --- /dev/null +++ b/bin/svn-push @@ -0,0 +1,157 @@ +#!/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 version specified in the plugin file. +# Author: Weston Ruter (@westonruter) + +set -e + +cd $(dirname $0)/.. + +if [ ! -e svn-url ]; then + echo "Error: Missing svn-url file" >&2 + exit 1 +fi + +force= +while getopts 'f' option; do + case $option in + f) + force=1 + ;; + esac +done + +if [ -n "$(git status -s -uno)" ] && [ -z "$force" ]; then + git status + echo "Error: Git state has modified or staged files. Commit or reset, or supply -f" >&2 + exit 1 +fi + +git_root=$(pwd) + +current_branch=$(git rev-parse --abbrev-ref HEAD) +if [ $current_branch != 'master' ]; then + git checkout master +fi + +bin/generate-markdown-readme +git add readme.md +if [ -n "$(git status --porcelain readme.md)" ]; then + echo "Please commit (--amend?) the updated readme.md" + exit 1 +fi + +git pull origin master +git push origin master +svn_url=$(cat svn-url) +svn_repo_dir=/tmp/svn-$(basename $git_root)-$(md5sum <<< $git_root | cut -c1-32) + +for php in *.php; do + if grep -q 'Plugin Name:' $php && grep -q 'Version:' $php; then + plugin_version=$(cat $php | grep 'Version:' | sed 's/.*Version: *//') + fi +done + +if [ -z "$plugin_version" ]; then + echo "Unable to find plugin version" + exit 1 +fi + +if ! grep -q "$plugin_version" readme.txt; then + echo "Please update readme.txt to include $plugin_version in changelog" + exit 1 +fi + +if git show-ref --tags --quiet --verify -- "refs/tags/$plugin_version"; then + has_tag=1 +fi + +if [ -n "$has_tag" ] && [ -z "$force" ]; then + echo "Plugin version $plugin_version already tagged. Please bump version and try again, or supply -f" + exit 1 +fi + +if [ -z "$has_tag" ]; then + echo "Tagging plugin version $plugin_version" + git tag "$plugin_version" master + git push origin "$plugin_version" +else + echo "Skipping plugin tag $plugin_version since already exists" +fi + +if [ -e $svn_repo_dir ] && [ ! -e $svn_repo_dir/.svn ]; then + rm -rf $svn_repo_dir +fi +if [ ! -e $svn_repo_dir ]; then + svn checkout $svn_url $svn_repo_dir + cd $svn_repo_dir +else + cd $svn_repo_dir + svn up +fi + +cd $git_root + +# rsync all cached files and their directories +cat <( + git ls-files --cached --full-name $git_root \ + & + git ls-files --cached --full-name $git_root | xargs -I {} dirname {} | sort | uniq +) | sort | rsync -avz --delete --delete-excluded --include-from=- --exclude='*' ./ $svn_repo_dir/trunk/ + +cd $svn_repo_dir/trunk + +# move assets directory to proper location in SVN +if [ -d assets ]; then + rsync -avz --delete ./assets/ ../assets/ + rm -r ./assets/ +fi + +# convert .gitignores to svn:ignore +for gitignore in $(find . -name .gitignore); do + echo "Convert $gitignore to svn:global-ignores" + svn propset svn:global-ignores -F $gitignore $(dirname $gitignore) + svn rm --force $gitignore +done + +cd $svn_repo_dir + +# Delete any files from SVN that are no longer there +svn status . | grep "^\!" | sed 's/^\! *//g' | xargs svn rm + +# Add everything left to commit +if [ -d assets ]; then + svn add --force assets +fi +svn add --force trunk + +# Do SVN commit +svn_commit_file=$svn_repo_dir/COMMIT_MSG +last_pushed_commit=$(svn log -l 1 | grep -E -o '^commit ([0-9a-f]{5,})' | head -n 1 | cut -c8-) + +cd $git_root + +git log -1 --format="Update to commit %h from $(git config --get remote.origin.url)" > $svn_commit_file +echo >> $svn_commit_file +echo 'Includes the following commit(s):' >> $svn_commit_file +echo >> $svn_commit_file + +echo -n 'Obtaining last commit pushed to SVN...' +git_log_args='--pretty=short --name-status --color=never' +if [ -z "$last_pushed_commit" ]; then + echo "none; starting from beginning" + git log $git_log_args >> $svn_commit_file +else + echo "$last_pushed_commit" + git log $git_log_args $last_pushed_commit..HEAD >> $svn_commit_file +fi + +cd $svn_repo_dir + +svn commit -F $svn_commit_file +rm $svn_commit_file + +# Restore branch +if [ $current_branch != 'master' ]; then + git checkout $current_branch +fi diff --git a/index.php b/index.php new file mode 100644 index 0000000..b928721 --- /dev/null +++ b/index.php @@ -0,0 +1,25 @@ + + * Author URI: http://codechutney.com + * Description: Adds one click approval option for comments in Gmail + * Version: 0.1 + * Text Domain : gia_inscub + */ +/** + * Used for Tranlation + */ +define( 'WP_GIA_TRANSLATION_DOMAIN', 'gia_inscub' ); + +foreach ( glob( dirname( __FILE__ ) . '/app/*.php' ) as $lib_filename ) { + require_once( $lib_filename ); +} +/** + *Create a instance of GmailInboxAction class + */ +function gia_initate_class() { + global $gmailinboxaction; + $gmailinboxaction = new GmailInboxAction(); +} +add_action( 'init', 'gia_initate_class' ); diff --git a/phpcs.ruleset.xml b/phpcs.ruleset.xml new file mode 120000 index 0000000..8f964bf --- /dev/null +++ b/phpcs.ruleset.xml @@ -0,0 +1 @@ +bin/phpcs.ruleset.xml \ No newline at end of file diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..bc42353 --- /dev/null +++ b/readme.txt @@ -0,0 +1,52 @@ +=== One Click Comment Approval for Gmail === +Contributors: UmeshSingla +Donate link: http://github.com/UmeshSingla +Tags: comment moderation, gmail actions +Requires at least: 3.8.1 +Tested up to: 3.8.1 +Stable tag: trunk +License: GPLv2 or later +License URI: http://www.gnu.org/licenses/gpl-2.0.html + +Allows you to approve your WordPress site comments from your inbox. + +== Description == + +This plugin incorporates the Gmail action API to WordPress comment approval. You can directly +approve the comments from your Gmail inbox without logging into your site. + +== Installation == + +1. Upload `gmail-inbox-action` folder to the `/wp-content/plugins/` directory +2. Activate the plugin through the 'Plugins' menu in WordPress +3. You should have https enabled for your site +3. For proper working you need to make sure that your emails are DKIM signed +4. Register your email with google: http://goo.gl/siU783 + +== Frequently Asked Questions == + += What is DKIM signed emails? = + +DKIM signatures are used to avoid spamming of mails, you can install it on +your server using this tutorial http://goo.gl/pKwTfl. + += Why I need to register with google? = + +Google keeps track of emails implementing Gmail actions to avoid spamming. + += Which email do i need to register ? = + +Register the email from which your server sends the email, to make sure the action +button is displayed + +== Other Notes == +Refer the following link to know more about registration : http://goo.gl/K9ArOP + +== Screenshots == + +1. Gmail screenshot + +== Changelog == + += 1.0 = +First Release \ No newline at end of file