This repository has been archived by the owner on Aug 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |