wip
This commit is contained in:
@ -65,7 +65,7 @@ class Comments extends Plugin {
|
||||
|
||||
public function __construct( $load = false ) {
|
||||
if ( !empty(App::$activePerms) ) {
|
||||
App::$isMod = !empty(App::$activePerms['modAccess']);
|
||||
App::$isMod = ! empty( App::$activePerms['modAccess'] );
|
||||
} else {
|
||||
App::$isMod = false;
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\Bedrock\Functions\Session;
|
||||
use TheTempusProject\Hermes\Functions\Redirect;
|
||||
use TheTempusProject\Models\Contact as ContactModel;
|
||||
use TheTempusProject\Plugins\Turnstile;
|
||||
|
||||
class Contact extends Controller {
|
||||
protected static $contact;
|
||||
@ -29,13 +30,28 @@ class Contact extends Controller {
|
||||
self::$contact = new ContactModel;
|
||||
self::$title = 'Contact - {SITENAME}';
|
||||
self::$pageDescription = 'At {SITENAME}, we value our users\' input. You can provide any contact or suggestions using this form.';
|
||||
if ( !Input::exists() ) {
|
||||
$turnstile = '';
|
||||
if ( class_exists( 'TheTempusProject\Plugins\Turnstile' ) ) {
|
||||
$turnstile = new Turnstile;
|
||||
if ( ! $turnstile->checkEnabled() ) {
|
||||
Components::set( 'TURNSTILE_WIDGET', '' );
|
||||
$turnstile = '';
|
||||
}
|
||||
} else {
|
||||
Components::set( 'TURNSTILE_WIDGET', '' );
|
||||
}
|
||||
if ( ! Input::exists() ) {
|
||||
return Views::view( 'contact.create' );
|
||||
}
|
||||
if ( !Forms::check( 'contact' ) ) {
|
||||
if ( ! Forms::check( 'contact' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your form, please check your submission and try again.' => Check::userErrors() ] );
|
||||
return Views::view( 'contact.create' );
|
||||
}
|
||||
if ( ! empty( $turnstile ) ) {
|
||||
if ( empty( $turnstile->verify() ) ) {
|
||||
return Views::view( 'contact.create' );
|
||||
}
|
||||
}
|
||||
$result = self::$contact->create( Input::post( 'name' ), Input::post( 'contactEmail' ), Input::post( 'entry' ) );
|
||||
if ( $result ) {
|
||||
Session::flash( 'success', 'Thank you! Your contact has been received.' );
|
||||
|
@ -40,6 +40,7 @@
|
||||
|
||||
<!-- Submit Button -->
|
||||
<div class="text-center">
|
||||
{TURNSTILE_WIDGET}
|
||||
<button type="submit" name="submit" value="submit" class="btn btn-primary btn-lg">Submit</button>
|
||||
</div>
|
||||
</form>
|
||||
|
@ -35,8 +35,6 @@ class Notifications extends AdminController {
|
||||
self::$notifications = new NotificationsModel;
|
||||
self::$user = new User;
|
||||
self::$group = new Group;
|
||||
$view = Navigation::activePageSelect( 'nav.admin', '/admin/Notifications' );
|
||||
Components::set( 'ADMINNAV', $view );
|
||||
}
|
||||
|
||||
public function index( $data = null ) {
|
||||
|
@ -121,21 +121,21 @@ class Notification extends DatabaseModel {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function filter( $messageArray, $filters = [] ) {
|
||||
public function filter( $entities, $filters = [] ) {
|
||||
$out = [];
|
||||
foreach ( $messageArray as $message ) {
|
||||
if ( !is_object( $message ) ) {
|
||||
$message = $messageArray;
|
||||
foreach ( $entities as $entity ) {
|
||||
if ( !is_object( $entity ) ) {
|
||||
$entity = $entities;
|
||||
$end = true;
|
||||
}
|
||||
if ( $message->seenAt == 0 ) {
|
||||
$message->unseenBadge = Views::simpleView( 'notifications.unseenBadge' );
|
||||
$message->markReadLink = '<a href="{ROOT_URL}notifications/markRead/'.$message->ID.'" class="btn btn-sm btn-primary"><i class="fa-solid fa-fw fa-envelope-open"></i></a>';
|
||||
if ( $entity->seenAt == 0 ) {
|
||||
$entity->unseenBadge = Views::simpleView( 'notifications.unseenBadge' );
|
||||
$entity->markReadLink = '<a href="{ROOT_URL}notifications/markRead/'.$entity->ID.'" class="btn btn-sm btn-primary"><i class="fa-solid fa-fw fa-envelope-open"></i></a>';
|
||||
} else {
|
||||
$message->unseenBadge = '';
|
||||
$message->markReadLink = '';
|
||||
$entity->unseenBadge = '';
|
||||
$entity->markReadLink = '';
|
||||
}
|
||||
$out[] = (object) $message;
|
||||
$out[] = (object) $entity;
|
||||
if ( !empty( $end ) ) {
|
||||
$out = $out[0];
|
||||
break;
|
||||
|
85
app/plugins/turnstile/plugin.php
Normal file
85
app/plugins/turnstile/plugin.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/turnstile/plugin.php
|
||||
*
|
||||
* This houses all of the main plugin info and functionality.
|
||||
*
|
||||
* @package TP Turnstile
|
||||
* @version 5.0.1
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Plugins;
|
||||
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
use TheTempusProject\Classes\Plugin;
|
||||
use TheTempusProject\Models\Notification;
|
||||
use TheTempusProject\Houdini\Classes\Components;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Bedrock\Classes\Config;
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\Houdini\Classes\Issues;
|
||||
|
||||
class Turnstile extends Plugin {
|
||||
private static $loaded = false;
|
||||
public $pluginName = 'TP Turnstile';
|
||||
public $pluginAuthor = 'JoeyK';
|
||||
public $pluginWebsite = 'https://TheTempusProject.com';
|
||||
public $modelVersion = '1.0';
|
||||
public $pluginVersion = '3.0';
|
||||
public $pluginDescription = 'A simple plugin which adds a site wide cloudflare turnstile integration.';
|
||||
public $configName = 'turnstile';
|
||||
public $configMatrix = [
|
||||
'secretKey' => [
|
||||
'type' => 'text',
|
||||
'pretty' => 'Turnstile Secret Key',
|
||||
'default' => 'xxxxxxxxxxxxx',
|
||||
],
|
||||
'apiKey' => [
|
||||
'type' => 'text',
|
||||
'pretty' => 'Turnstile API Key',
|
||||
'default' => 'xxxxxxxxxxxxxx',
|
||||
],
|
||||
];
|
||||
|
||||
public function __construct( $load = false ) {
|
||||
parent::__construct( $load );
|
||||
if ( ! self::$loaded ) {
|
||||
if ( $this->checkEnabled() ) {
|
||||
Components::set( 'TURNSTILE_API_KEY', Config::getValue( 'turnstile/apiKey' ) );
|
||||
Components::set( 'TURNSTILE_WIDGET', Views::simpleView( 'turnstile.widget') );
|
||||
Components::append( 'TEMPLATE_JS_INCLUDES', '<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>' );
|
||||
}
|
||||
self::$loaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function verify() {
|
||||
if ( ! Input::exists('cf-turnstile-response') ) {
|
||||
Issues::add( 'notice', 'Turnstile verification failed. Please try again.' );
|
||||
return false;
|
||||
}
|
||||
$verify_url = "https://challenges.cloudflare.com/turnstile/v0/siteverify";
|
||||
$data = [
|
||||
"secret" => Config::getValue( 'turnstile/secretKey' ),
|
||||
"response" => Input::post('cf-turnstile-response'),
|
||||
"remoteip" => $_SERVER["REMOTE_ADDR"] // Optional, helps detect abuse
|
||||
];
|
||||
$options = [
|
||||
"http" => [
|
||||
"header" => "Content-Type: application/x-www-form-urlencoded",
|
||||
"method" => "POST",
|
||||
"content" => http_build_query($data)
|
||||
]
|
||||
];
|
||||
$context = stream_context_create($options);
|
||||
$response = file_get_contents($verify_url, false, $context);
|
||||
$result = json_decode($response, true);
|
||||
if ( ! $result["success"]) {
|
||||
Issues::add( 'notice', 'Turnstile verification failed. Please try again. If the issue persists, please contact the site administrator.' );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
1
app/plugins/turnstile/views/widget.html
Normal file
1
app/plugins/turnstile/views/widget.html
Normal file
@ -0,0 +1 @@
|
||||
<div class="cf-turnstile" data-sitekey="{TURNSTILE_API_KEY}"></div>
|
Reference in New Issue
Block a user