- Fixes issue with ucwords() function on older PHP versions
- Updates Supervisor/Daemon to strip port from site_url() when it's running on localhost inside a virtual machine :)
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
namespace MailPoet\Config;
|
namespace MailPoet\Config;
|
||||||
|
|
||||||
use MailPoet\Queue\Daemon;
|
use MailPoet\Queue\Daemon;
|
||||||
|
use MailPoet\Util\Helpers;
|
||||||
|
|
||||||
if(!defined('ABSPATH')) exit;
|
if(!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
@@ -11,7 +12,7 @@ class PublicAPI {
|
|||||||
$this->api = isset($_GET['mailpoet-api']) ? true : false;
|
$this->api = isset($_GET['mailpoet-api']) ? true : false;
|
||||||
$this->section = isset($_GET['section']) ? $_GET['section'] : false;
|
$this->section = isset($_GET['section']) ? $_GET['section'] : false;
|
||||||
$this->action = isset($_GET['action']) ?
|
$this->action = isset($_GET['action']) ?
|
||||||
str_replace('_', '', lcfirst(ucwords($_GET['action'], '_'))) :
|
Helpers::underscoreToCamelCase($_GET['action']) :
|
||||||
false;
|
false;
|
||||||
$this->payload = isset($_GET['payload']) ?
|
$this->payload = isset($_GET['payload']) ?
|
||||||
json_decode(urldecode($_GET['payload']), true) :
|
json_decode(urldecode($_GET['payload']), true) :
|
||||||
|
@@ -85,7 +85,7 @@ class Daemon {
|
|||||||
'user-agent' => 'MailPoet (www.mailpoet.com)'
|
'user-agent' => 'MailPoet (www.mailpoet.com)'
|
||||||
);
|
);
|
||||||
wp_remote_get(
|
wp_remote_get(
|
||||||
site_url() .
|
Supervisor::getSiteUrl() .
|
||||||
'/?mailpoet-api§ion=queue&action=run&payload=' . urlencode($payload),
|
'/?mailpoet-api§ion=queue&action=run&payload=' . urlencode($payload),
|
||||||
$args
|
$args
|
||||||
);
|
);
|
||||||
|
@@ -52,7 +52,7 @@ class Supervisor {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
wp_remote_get(
|
wp_remote_get(
|
||||||
site_url() .
|
self::getSiteUrl() .
|
||||||
'/?mailpoet-api§ion=queue&action=start&payload=' .
|
'/?mailpoet-api§ion=queue&action=start&payload=' .
|
||||||
urlencode($payload),
|
urlencode($payload),
|
||||||
$args
|
$args
|
||||||
@@ -87,4 +87,13 @@ class Supervisor {
|
|||||||
throw new \Exception('Database has not been configured.');
|
throw new \Exception('Database has not been configured.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function getSiteUrl() {
|
||||||
|
if(!preg_match('!:/!', site_url())) return site_url();
|
||||||
|
preg_match('!http://(?P<host>.*?):(?P<port>\d+)!', site_url(), $server);
|
||||||
|
$fp = fsockopen($server['host'], $server['port'], $errno, $errstr, 1);
|
||||||
|
return ($fp) ?
|
||||||
|
site_url() :
|
||||||
|
preg_replace('/(?=:\d+):\d+/', '$1', site_url());
|
||||||
|
}
|
||||||
}
|
}
|
@@ -76,12 +76,18 @@ class Helpers {
|
|||||||
static function getMaxPostSize($bytes = false) {
|
static function getMaxPostSize($bytes = false) {
|
||||||
$maxPostSize = ini_get('post_max_size');
|
$maxPostSize = ini_get('post_max_size');
|
||||||
if(!$bytes) return $maxPostSize;
|
if(!$bytes) return $maxPostSize;
|
||||||
switch (substr ($maxPostSize, -1))
|
switch (substr($maxPostSize, -1)) {
|
||||||
{
|
case 'M':
|
||||||
case 'M': case 'm': return (int)$maxPostSize * 1048576;
|
case 'm':
|
||||||
case 'K': case 'k': return (int)$maxPostSize * 1024;
|
return (int) $maxPostSize * 1048576;
|
||||||
case 'G': case 'g': return (int)$maxPostSize * 1073741824;
|
case 'K':
|
||||||
default: return $maxPostSize;
|
case 'k':
|
||||||
|
return (int) $maxPostSize * 1024;
|
||||||
|
case 'G':
|
||||||
|
case 'g':
|
||||||
|
return (int) $maxPostSize * 1073741824;
|
||||||
|
default:
|
||||||
|
return $maxPostSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,4 +170,12 @@ class Helpers {
|
|||||||
}
|
}
|
||||||
return $resultArray;
|
return $resultArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function underscoreToCamelCase($str, $capitalise_first_char = false) {
|
||||||
|
if($capitalise_first_char) {
|
||||||
|
$str[0] = strtoupper($str[0]);
|
||||||
|
}
|
||||||
|
$func = create_function('$c', 'return strtoupper($c[1]);');
|
||||||
|
return preg_replace_callback('/_([a-z])/', $func, $str);
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user