';
public static function getSubscribedEvents()
{
return [
'onPluginsInitialized' => ['onPluginsInitialized', 0]
];
}
//public function onPluginsInitialized(Event $event)
public function onPluginsInitialized()
{
$this->enable([
'onPageInitialized' => ['onPageInitialized', 0]
]);
}
public function onPageInitialized()
{
$this->mergeConfig($this->grav['page']);
if ( $this->config->get('plugins.twitty.enabled') ) {
$page = $this->grav['page'];
$twig = $this->grav['twig'];
$uri = $this->grav['uri'];
$options = $this->config->get('plugins.twitty');
$twittyUsername = $this->config->get('plugins.twitty.twittyUsername');
//Read page and replace
$page->content($this->processHtml($page,$twittyUsername));
}
}
private function processHtml($page,$twittyUsername)
{
$content = $page->content();
$replace = array('TWITTYTEXT'=>$this->code,'TWITTYNAME'=>$twittyUsername);
return str_replace(array_keys($replace),array_values($replace), $content);
}
private function mergeConfig( Page $page )
{
$defaults = (array) $this->config->get('plugins.twitty');
if ( isset($page->header()->twitty) ) {
$this->config->set('plugins.twitty.enabled', true);
} else {
$this->config->set('plugins.twitty.enabled', false);
}
}
}
?>