Skip to content

Commit

Permalink
Fix panel routes
Browse files Browse the repository at this point in the history
Closes #42
  • Loading branch information
pedroborges committed Mar 1, 2018
1 parent 4e3ec51 commit f1732b3
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 24 deletions.
6 changes: 2 additions & 4 deletions autogit.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Kirby Auto Git Plugin
*
* @version 0.6.0
* @version 0.6.1
* @author Pedro Borges <[email protected]>
* @copyright Pedro Borges <[email protected]>
* @link https://github.com/pedroborges/kirby-autogit
Expand All @@ -21,9 +21,7 @@ function autogit() {
}

// Load routes
if (c::get('autogit.webhook.secret', false)) {
require_once(__DIR__.DS.'lib'.DS.'routes.php');
}
require_once(__DIR__.DS.'lib'.DS.'routes.php');

// Only load hooks, routes and widgets when
// the content directory is a Git repo
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Change Log
All notable changes to this project will be documented in this file.

## [0.6.1] - 2018-03-01
### Fixed
- Bug where panel routes where not being registered.

## [0.6.0] - 2018-02-13
### Added
- `autogit` option: disables the plugin.
Expand Down
Empty file modified lib/autogit.php
100644 → 100755
Empty file.
Empty file modified lib/hooks.php
100644 → 100755
Empty file.
36 changes: 20 additions & 16 deletions lib/routes.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function autogitRoute($action, $source = null) {
}

// Add widget route
if (class_exists('Panel')) {
if (function_exists('panel')) {
panel()->routes([
[
'pattern' => 'autogit/(:any)',
Expand All @@ -36,19 +36,23 @@ function autogitRoute($action, $source = null) {
}

// Add webhook route
kirby()->routes([
[
'pattern' => c::get('autogit.webhook.url', 'autogit').'/(:any)',
'method' => 'GET|POST',
'action' => function($action) {
$secretMatches = r::get('secret') === c::get('autogit.webhook.secret');
$validActions = ['pull', 'push'];

if (! autogit()->hasRemote() or ! $secretMatches or ! in_array($action, $validActions)) {
return go(site()->errorPage());
}
if (c::get('autogit.webhook.secret', false)) {
kirby()->routes([
[
'pattern' => c::get('autogit.webhook.url', 'autogit').'/(:any)',
'method' => 'GET|POST',
'action' => function($action) {
$secretMatches = r::get('secret') === c::get('autogit.webhook.secret');
$validActions = ['pull', 'push'];

if (! autogit()->hasRemote() or
! $secretMatches or
! in_array($action, $validActions)) {
return go(site()->errorPage());
}

return autogitRoute($action, 'webhook');
}
]
]);
return autogitRoute($action, 'webhook');
}
]
]);
}
Empty file modified lib/translations.php
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "autogit",
"author": "Pedro Borges <[email protected]>",
"version": "0.6.0",
"version": "0.6.1",
"description": "Kirby Auto Git",
"type": "kirby-plugin",
"license": "MIT"
Expand Down
6 changes: 3 additions & 3 deletions widgets/autogit/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@

<div class="autogit-widget">
<?php if (autogit()->hasRemote()) : ?>
<button href="/panel/autogit/push" data-action="push" class="btn btn-rounded btn-positive autogit-action">
<button data-action="push" class="btn btn-rounded btn-positive autogit-action">
<i class="icon icon-left fa fa-cloud-upload"></i>
Publish changes
</button>
<button href="/panel/autogit/pull" data-action="pull" class="btn btn-rounded btn-positive autogit-action">
<button data-action="pull" class="btn btn-rounded btn-positive autogit-action">
<i class="icon icon-left fa fa-cloud-download"></i>
Get latest changes
</button>
Expand All @@ -67,7 +67,7 @@
</div>

<script>
var panelURL = '<?php echo panel()->urls->index ?>'
var panelURL = '<?= panel()->urls->index ?>'
var $widget = $('#autogit-widget')
var $loadingIcon = $('<i class="icon icon-left fa fa-spinner" />')
var $successIcon = $('<i class="icon icon-left fa fa-check" />')
Expand Down

0 comments on commit f1732b3

Please sign in to comment.