praiadeseselle/site/ready.php

61 lines
No EOL
1.7 KiB
PHP

<?php namespace ProcessWire;
if(!defined("PROCESSWIRE")) die();
/** @var ProcessWire $wire */
/**
* ProcessWire Bootstrap API Ready
* ===============================
* This ready.php file is called during ProcessWire bootstrap initialization process.
* This occurs after the current page has been determined and the API is fully ready
* to use, but before the current page has started rendering. This file receives a
* copy of all ProcessWire API variables.
*
*/
/*function str_lreplace($search, $replace, $subject)
{
return preg_replace('~(.*)' . preg_quote($search, '~') . '~', '$1' . $replace, $subject, 1);
}
function str_freplace($search, $replace, $subject)
{
$from = '/'.preg_quote($search, '/').'/';
return preg_replace($from, $replace, $subject, 1);
}
$captcha = wire('modules')->get("MarkupGoogleRecaptcha");
wire()->addHookProperty('Page::captcha', function($event) use ($captcha)
{
$event->return = $captcha;
});
wire()->addHookAfter('Page::render', function($event)
{
$template = $event->object->template;
$page = $event->object;
if($template == 'admin' && !wire('user')->isLoggedin())
{
$event->return = str_freplace('</form>', $page->captcha->render() . '</form>', $event->return);
$event->return = str_lreplace('</body>', $page->captcha->getScript() . '</body>', $event->return);
}
});
wire()->addHookAfter('Session::authenticate', function($event)
{
$page = wire('page');
$template = $page->template;
if($template == 'admin')
{
if($page->captcha->verifyResponse() == false)
{
wire('session')->logout();
wire('session')->redirect(wire('config')->urls->admin);
}
}
});*/