Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Commit

Permalink
blackhole.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Barry authored and Barry committed Jul 26, 2017
1 parent cf04c32 commit f9d31a0
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions blackhole.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
namespace Grav\Plugin;

use Grav\Common\Plugin;
use Grav\Common\Grav;
use Grav\Common\Page\Page;

class BlackholePlugin extends Plugin {
public $content;

public static function getSubscribedEvents() {
return [
'onPageInitialized' => ['onPageInitialized', 0],
'onOutputRendered' => ['onOutputRendered', 0]
];
}

public function onPageInitialized() {
if (!empty($_GET['pages']) && $_GET['pages'] == 'all') {
ob_start();

// get output_path from plugin settings
$output_path = $this->config->get('plugins.blackhole.output_path');

// get all routes from grav
$routes = $this->grav['pages']->routes();

if (!empty($_GET['output_path'])) {
$this->content = $output_path;
} else {
$this->content = json_encode($routes, JSON_UNESCAPED_SLASHES);
}
}
}

public function onOutputRendered() {
// publish page routes
if (!empty($_GET['pages']) && $_GET['pages'] == 'all') {
ob_end_clean();
echo $this->content;
}
}
}

0 comments on commit f9d31a0

Please sign in to comment.