<?php
/*
Plugin Name: Viewer Links Patch
Description: Modifies viewer links so that the PHP security workaround (from May 2012) that disallows urls with - but not = won't break URLs
Version: 1.00
Requires at least: 1.28
*/

/*
 From: http://www.php.net/archive/2012.php#id2012-05-06-1
 One way to address these CGI issues is to reject the request if the query string contains a '-' and no '='.
 It can be done using Apache's mod_rewrite like this: See: http://www.php.net/archive/2012.php#id2012-05-06-1
 Note that this will block otherwise safe requests like ?top-40 so if you have query parameters that look like that, adjust your regex accordingly.

 Since we can't always control how hosts patch or modify their servers this plugin adds a equals to URLs to avoid the above issue.
*/

addFilter('viewer_link_field_content', 'viewerLinks_workaroundPhpPatch', null, 2);

//
function viewerLinks_workaroundPhpPatch($defaultOutput, $fieldValue) {
  $output = 'p=' . $defaultOutput; // adding an equals bypasses the filter
  return $output;
}

?>
