From 1836f737f9522a91e2b9cb6816c4d06ce25e626e Mon Sep 17 00:00:00 2001 From: montdidier Date: Thu, 21 May 2015 11:05:16 +0800 Subject: [PATCH 1/5] basic support for json in body of webhooks --- includes.php | 31 +++++++++++++++++++++++++++++-- options.php | 4 +++- services.php | 4 +++- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/includes.php b/includes.php index 467b3d7..873007f 100644 --- a/includes.php +++ b/includes.php @@ -3,6 +3,12 @@ require('services.php'); require('hooks.php'); +function split_header($carry, $item) { + list($key, $value) = explode(":", $item); + $carry[trim($key)] = trim($value); + return $carry; +} + // OPTIONS function hookpress_get_fields( $type ) { @@ -123,6 +129,24 @@ function hookpress_print_edit_webhook( $id ){ ?> + + + + +">

@@ -314,8 +338,11 @@ function hookpress_generic_action($id,$args) { $obj_to_post['hook'] = $desc['hook']; $user_agent = "HookPress/{$hookpress_version} (compatible; WordPress {$wp_version}; +http://mitcho.com/code/hookpress/)"; - - $request = apply_filters( 'hookpress_request', array('user-agent' => $user_agent, 'body' => $obj_to_post, 'referer' => get_bloginfo('url')) ); + $headers = array_reduce($desc['headers'], 'split_header', array()); + $content_type = empty($desc['contenttype']) ? 'application/x-www-form-urlencoded; charset=UTF-8' : $desc['contenttype']; + $headers = array_merge($headers, array('Content-Type' => $content_type)); + + $request = apply_filters( 'hookpress_request', array('headers' => $headers, 'user-agent' => $user_agent, 'body' => $content_type == 'application/json' ? json_encode($obj_to_post) : $obj_to_post, 'referer' => get_bloginfo('url')) ); return wp_remote_post($desc['url'], $request); } diff --git a/options.php b/options.php index 062c9ff..08c4e27 100755 --- a/options.php +++ b/options.php @@ -111,12 +111,14 @@ tb.find('#editindicator').html('
 
'); id = tb.find('#edit-hook-id').val(); - + $.ajax({type: 'POST', url:'admin-ajax.php', data:'action=hookpress_add_fields' +'&fields='+tb.find('#editfields').val().join() +'&url='+tb.find('#editurl').val() + +'&contenttype='+tb.find('#editcontenttype').val() + +'&headers='+tb.find('#editheaders').val() +'&type='+tb.find('.newtype:checked').attr('id') +'&hook='+tb.find('#edithook').val() +'&enabled='+tb.find('#enabled').val() diff --git a/services.php b/services.php index 8f6b9c0..c391f03 100644 --- a/services.php +++ b/services.php @@ -46,7 +46,9 @@ function hookpress_ajax_add_fields() { 'type'=>$_POST['type'], 'hook'=>$_POST['hook'], 'enabled'=>$_POST['enabled'], - 'fields'=>split(',',$_POST['fields']) + 'contenttype'=>$_POST['contenttype'], + 'fields'=>split(',',$_POST['fields']), + 'headers'=>split(',',$_POST['headers']) ); hookpress_update_hook( $id, $edithook ); From 58074518f9fcf073dcb4749a160068496789f47d Mon Sep 17 00:00:00 2001 From: montdidier Date: Thu, 21 May 2015 11:09:10 +0800 Subject: [PATCH 2/5] updated release notes and version number --- hookpress.php | 4 ++-- readme.txt | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/hookpress.php b/hookpress.php index 9cab3ee..f8fc2b1 100644 --- a/hookpress.php +++ b/hookpress.php @@ -3,14 +3,14 @@ Plugin Name: HookPress Plugin URI: http://mitcho.com/code/hookpress/ Description: HookPress turns all of your WordPress-internal hooks into webhooks. Possible uses include generating push notifications or using non-PHP web technology to extend WordPress. Read more about webhooks at the webhooks site. -Version: 1.14 +Version: 1.15 Author: mitcho (Michael Yoshitaka Erlewine) Author URI: http://mitcho.com/ Donate link: http://tinyurl.com/donatetomitcho */ define('HOOKPRESS_PRIORITY',12838790321); -$hookpress_version = "1.14"; +$hookpress_version = "1.15"; require('includes.php'); function hookpress_init() { diff --git a/readme.txt b/readme.txt index 110dc8d..8fa1155 100644 --- a/readme.txt +++ b/readme.txt @@ -39,6 +39,8 @@ If you have a feature request or question, please use the [HookPress support for HookPress currently makes requests synchronously so can measurably affect performance. I highly recommend using a caching plugin such as [WP-SuperCache](http://ocaoimh.ie/wp-super-cache/) to stem the performance hit. If your filters' results are time-sensitive or dependent on external data sources as well, make sure to set an appropriate cache expiration time. == Changelog == += 1.15 = +* Added basic support JSON bodied webshooks and header based authentication = 1.14 = * Additional security hardening for `test.php`, now no longer bundled as a `.php` From c967cfb0a79f9ec0ad5742370ad7ccc9729b5ae7 Mon Sep 17 00:00:00 2001 From: montdidier Date: Fri, 22 May 2015 11:01:43 +0800 Subject: [PATCH 3/5] show nothing and do not cause an error when headers field is empty --- includes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes.php b/includes.php index 873007f..6910653 100644 --- a/includes.php +++ b/includes.php @@ -146,7 +146,7 @@ function hookpress_print_edit_webhook( $id ){ ?> -"> +">

From debdb6da9414564a2ebc94c029a0dacd0fb23d41 Mon Sep 17 00:00:00 2001 From: Chris Kruger Date: Fri, 11 May 2018 10:40:30 +0800 Subject: [PATCH 4/5] updated readme.txt sp. and grammar --- readme.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/readme.txt b/readme.txt index 8fa1155..4e689c2 100644 --- a/readme.txt +++ b/readme.txt @@ -40,7 +40,7 @@ HookPress currently makes requests synchronously so can measurably affect perfor == Changelog == = 1.15 = -* Added basic support JSON bodied webshooks and header based authentication +* Added basic support for JSON webhooks and header based authentication. = 1.14 = * Additional security hardening for `test.php`, now no longer bundled as a `.php` @@ -64,12 +64,12 @@ HookPress currently makes requests synchronously so can measurably affect perfor * added webhook editing * Various miscellaneous features: added nonces for security, modularized the code a bit, etc. = 0.1.8 = -* Added more filtersÑnow covers basic + comment filters +* Added more filtersÑnow covers basic + comment filters * Marking as compatible through 2.9.9, because it should be. * Added version checking and beta offers to the options screen. = 0.1.7 = * Now supports basically all actions. (Still no actions with no arguments.) -* Added more filter optionsÑnow covers all basic database read filters. +* Added more filter optionsÑnow covers all basic database read filters. = 0.1.6 = * Added another batch of actions. (Still no actions with no arguments, though... something to consider.) * Fixed hooks which referred to the users and links tables. From fbab0c6be454e29424fdc01475fb6a89496330bf Mon Sep 17 00:00:00 2001 From: Chris Kruger Date: Fri, 11 May 2018 10:42:06 +0800 Subject: [PATCH 5/5] Updated readme.txt; non UTF-8 characters --- readme.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.txt b/readme.txt index 4e689c2..0213d8a 100644 --- a/readme.txt +++ b/readme.txt @@ -64,12 +64,12 @@ HookPress currently makes requests synchronously so can measurably affect perfor * added webhook editing * Various miscellaneous features: added nonces for security, modularized the code a bit, etc. = 0.1.8 = -* Added more filtersÑnow covers basic + comment filters +* Added more filters, now covers basic + comment filters * Marking as compatible through 2.9.9, because it should be. * Added version checking and beta offers to the options screen. = 0.1.7 = * Now supports basically all actions. (Still no actions with no arguments.) -* Added more filter optionsÑnow covers all basic database read filters. +* Added more filter options, now covers all basic database read filters. = 0.1.6 = * Added another batch of actions. (Still no actions with no arguments, though... something to consider.) * Fixed hooks which referred to the users and links tables.