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

View File

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

View File

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

View File

@ -46,7 +46,7 @@ class pluginAPI extends Plugin {
// CHECK URL // CHECK URL
// ------------------------------------------------------------ // ------------------------------------------------------------
$URI = $this->webhook('api', $returnsAfterURI=true); $URI = $this->webhook('api', $returnsAfterURI=true, $fixed=false);
if ($URI===false) { if ($URI===false) {
return 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; 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; $webhook = 'rss.xml';
if( $this->webhook($webhook) ) {
if($Url->uri()===HTML_PATH_ROOT.'rss.xml') {
// Send XML header // Send XML header
header('Content-type: text/xml'); header('Content-type: text/xml');
$doc = new DOMDocument(); $doc = new DOMDocument();
@ -118,5 +117,4 @@ class pluginRSS extends Plugin {
exit(0); exit(0);
} }
} }
} }

View File

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