bug fixes on webhooks

This commit is contained in:
Diego Najar 2017-07-29 01:20:47 +02:00
parent fdca541194
commit 21fafa9082
6 changed files with 24 additions and 18 deletions

View File

@ -276,11 +276,11 @@ class Plugin {
// Returns the parameters after the URI, FALSE if the URI doesn't match with the webhook
// Example: https://www.mybludit.com/api/foo/bar
public function webhook($URI=false, $returnsAfterURI=false)
public function webhook($URI=false, $returnsAfterURI=false, $fixed=true)
{
global $Url;
if(empty($URI)) {
if (empty($URI)) {
return false;
}
@ -288,12 +288,22 @@ class Plugin {
$startString = HTML_PATH_ROOT.$URI;
$URI = $Url->uri();
$length = mb_strlen($startString, CHARSET);
if( mb_substr($URI, 0, $length)!=$startString ) {
if (mb_substr($URI, 0, $length)!=$startString) {
return false;
}
if($returnsAfterURI) {
return mb_substr($URI, $length);
$afterURI = mb_substr($URI, $length);
if (!empty($afterURI)) {
if ($fixed) {
return false;
}
if ($afterURI[0]!='/') {
return false;
}
}
if ($returnsAfterURI) {
return $afterURI;
}
Log::set(__METHOD__.LOG_SEP.'Webhook requested.');

View File

@ -111,7 +111,7 @@ define('CLI_STATUS', 'published');
define('CLI_USERNAME', 'admin');
// Filename
define('FILENAME', 'index.txt');
define('FILENAME', 'index.md');
// Database date format
define('DB_DATE_FORMAT', 'Y-m-d H:i:s');

View File

@ -265,7 +265,7 @@ function createPage($args) {
}
$key = $dbPages->add($args);
if($key) {
if ($key) {
// Call the plugins after page created
Theme::plugins('afterPageCreate');

View File

@ -46,7 +46,7 @@ class pluginAPI extends Plugin {
// CHECK URL
// ------------------------------------------------------------
$URI = $this->webhook('api', $returnsAfterURI=true);
$URI = $this->webhook('api', $returnsAfterURI=true, $fixed=false);
if ($URI===false) {
return false;
}

View File

@ -97,11 +97,10 @@ class pluginRSS extends Plugin {
return '<link rel="alternate" type="application/rss+xml" href="'.DOMAIN_BASE.'rss.xml" title="RSS Feed">'.PHP_EOL;
}
public function beforeRulesLoad()
public function beforeAll()
{
global $Url;
if($Url->uri()===HTML_PATH_ROOT.'rss.xml') {
$webhook = 'rss.xml';
if( $this->webhook($webhook) ) {
// Send XML header
header('Content-type: text/xml');
$doc = new DOMDocument();
@ -118,5 +117,4 @@ class pluginRSS extends Plugin {
exit(0);
}
}
}

View File

@ -62,11 +62,10 @@ class pluginSitemap extends Plugin {
$this->createXML();
}
public function beforeRulesLoad()
public function beforeAll()
{
global $Url;
if($Url->uri()===HTML_PATH_ROOT.'sitemap.xml') {
$webhook = 'sitemap.xml';
if( $this->webhook($webhook) ) {
// Send XML header
header('Content-type: text/xml');
$doc = new DOMDocument();
@ -86,5 +85,4 @@ class pluginSitemap extends Plugin {
exit(0);
}
}
}