remove unused plugins and code
This commit is contained in:
@ -1,63 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/bugreport/controllers/admin/bugreport.php
|
||||
*
|
||||
* This is the bug report admin controller.
|
||||
*
|
||||
* @package TP BugReports
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Controllers\Admin;
|
||||
|
||||
use TheTempusProject\Classes\AdminController;
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\Houdini\Classes\Issues;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Houdini\Classes\Navigation;
|
||||
use TheTempusProject\Houdini\Classes\Components;
|
||||
use TheTempusProject\Models\Bugreport as BugreportModel;
|
||||
|
||||
class Bugreport extends AdminController {
|
||||
protected static $bugreport;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$bugreport = new BugreportModel;
|
||||
self::$title = 'Admin - Bug Reports';
|
||||
$view = Navigation::activePageSelect( 'nav.admin', '/admin/bugreport' );
|
||||
Components::set( 'ADMINNAV', $view );
|
||||
}
|
||||
|
||||
public function index( $data = null ) {
|
||||
Views::view( 'bugreport.admin.list', self::$bugreport->listPaginated() );
|
||||
}
|
||||
|
||||
public function view( $id = null ) {
|
||||
$data = self::$bugreport->findById( $id );
|
||||
if ( $data !== false ) {
|
||||
return Views::view( 'bugreport.admin.view', $data );
|
||||
}
|
||||
Issues::add( 'error', 'Report not found.' );
|
||||
$this->index();
|
||||
}
|
||||
|
||||
public function delete( $data = null ) {
|
||||
if ( Input::exists( 'submit' ) ) {
|
||||
$data = Input::post( 'BR_' );
|
||||
}
|
||||
if ( self::$bugreport->delete( (array) $data ) ) {
|
||||
Issues::add( 'success', 'Bug Report Deleted' );
|
||||
} else {
|
||||
Issues::add( 'error', 'There was an error with your request.' );
|
||||
}
|
||||
$this->index();
|
||||
}
|
||||
|
||||
public function clear( $data = null ) {
|
||||
self::$bugreport->empty();
|
||||
$this->index();
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/bugreport/controllers/bugreport.php
|
||||
*
|
||||
* This is the bug reports controller.
|
||||
*
|
||||
* @package TP BugReports
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Controllers;
|
||||
|
||||
use TheTempusProject\Hermes\Functions\Redirect;
|
||||
use TheTempusProject\Bedrock\Functions\Check;
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\Bedrock\Functions\Session;
|
||||
use TheTempusProject\Houdini\Classes\Issues;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Classes\Controller;
|
||||
use TheTempusProject\Classes\Forms;
|
||||
use TheTempusProject\Models\Bugreport as BugreportModel;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
|
||||
class Bugreport extends Controller {
|
||||
protected static $bugreport;
|
||||
|
||||
public function index() {
|
||||
self::$bugreport = new BugreportModel;
|
||||
self::$title = 'Bug Report - {SITENAME}';
|
||||
self::$pageDescription = 'On this page you can submit a bug report for the site.';
|
||||
if ( !App::$isLoggedIn ) {
|
||||
return Issues::add( 'notice', 'You must be logged in to report bugs.' );
|
||||
}
|
||||
if ( !Input::exists() ) {
|
||||
return Views::view( 'bugreport.create' );
|
||||
}
|
||||
if ( !Forms::check( 'bugreport' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your report.' => Check::userErrors() ] );
|
||||
return Views::view( 'bugreport.create' );
|
||||
}
|
||||
$result = self::$bugreport->create( App::$activeUser->ID, Input::post( 'url' ), Input::post( 'ourl' ), Input::post( 'repeat' ), Input::post( 'entry' ) );
|
||||
if ( false != $result ) {
|
||||
Session::flash( 'success', 'Your Bug Report has been received. We may contact you for more information at the email address you provided.' );
|
||||
Redirect::to( 'home/index' );
|
||||
} else {
|
||||
Issues::add( 'error', 'There was an unresolved error while submitting your report.' );
|
||||
return Views::view( 'bugreport.create' );
|
||||
}
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/bugreport/forms.php
|
||||
*
|
||||
* This houses all of the form checking functions for this plugin.
|
||||
*
|
||||
* @package TP BugReports
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Plugins\Bugreport;
|
||||
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\Classes\Forms;
|
||||
|
||||
class BugReportForms extends Forms {
|
||||
/**
|
||||
* Adds these functions to the form list.
|
||||
*/
|
||||
public function __construct() {
|
||||
self::addHandler( 'bugreport', __CLASS__, 'bugreport' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the bug report form.
|
||||
*
|
||||
* @return {bool}
|
||||
*/
|
||||
public static function bugreport() {
|
||||
if ( !self::url( Input::post( 'url' ) ) ) {
|
||||
self::addUserError( 'Invalid url.' );
|
||||
return false;
|
||||
}
|
||||
if ( !self::url( Input::post( 'ourl' ) ) ) {
|
||||
self::addUserError( 'Invalid original url.' );
|
||||
return false;
|
||||
}
|
||||
if ( !self::tf( Input::post( 'repeat' ) ) ) {
|
||||
self::addUserError( 'Invalid repeat value.' );
|
||||
return false;
|
||||
}
|
||||
if ( !self::token() ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
new BugReportForms;
|
@ -1,100 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/bugreport/models/bugreport.php
|
||||
*
|
||||
* This class is used for the manipulation of the bugreports database table.
|
||||
*
|
||||
* @package TP BugReports
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Models;
|
||||
|
||||
use TheTempusProject\Bedrock\Functions\Check;
|
||||
use TheTempusProject\Canary\Bin\Canary as Debug;
|
||||
use TheTempusProject\Canary\Classes\CustomException;
|
||||
use TheTempusProject\Classes\DatabaseModel;
|
||||
use TheTempusProject\Plugins\Bugreport as Plugin;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
|
||||
class Bugreport extends DatabaseModel {
|
||||
public $tableName = 'bugreports';
|
||||
public $databaseMatrix = [
|
||||
[ 'userID', 'int', '11' ],
|
||||
[ 'time', 'int', '10' ],
|
||||
[ 'repeat', 'varchar', '5' ],
|
||||
[ 'ourl', 'varchar', '256' ],
|
||||
[ 'url', 'varchar', '256' ],
|
||||
[ 'ip', 'varchar', '15' ],
|
||||
[ 'description', 'text', '' ],
|
||||
];
|
||||
public $plugin;
|
||||
|
||||
/**
|
||||
* The model constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->plugin = new Plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function parses the bug reports description and
|
||||
* separates it into separate keys in the array.
|
||||
*
|
||||
* @param array $data - The data being parsed.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function filter( $data, $params = [] ) {
|
||||
foreach ( $data as $instance ) {
|
||||
if ( !is_object( $instance ) ) {
|
||||
$instance = $data;
|
||||
$end = true;
|
||||
}
|
||||
$instance->submittedBy = self::$user->getUsername( $instance->userID );
|
||||
$instance->repeatText = ( $instance->repeat ? 'yes' : 'no' );
|
||||
$out[] = $instance;
|
||||
if ( !empty( $end ) ) {
|
||||
$out = $out[0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a Bug Report form.
|
||||
*
|
||||
* @param int $ID the user ID submitting the form
|
||||
* @param string $url the url
|
||||
* @param string $o_url the original url
|
||||
* @param int $repeat is repeatable?
|
||||
* @param string $description_ description of the event.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function create( $ID, $url, $oUrl, $repeat, $description ) {
|
||||
if ( !$this->plugin->checkEnabled() ) {
|
||||
Debug::info( 'Bug Reporting is disabled in the config.' );
|
||||
return false;
|
||||
}
|
||||
$fields = [
|
||||
'userID' => App::$activeUser->ID,
|
||||
'time' => time(),
|
||||
'repeat' => $repeat,
|
||||
'ourl' => $oUrl,
|
||||
'url' => $url,
|
||||
'ip' => $_SERVER['REMOTE_ADDR'],
|
||||
'description' => $description,
|
||||
];
|
||||
if ( !self::$db->insert( $this->tableName, $fields ) ) {
|
||||
new CustomException( 'bugreportsCreate' );
|
||||
|
||||
return false;
|
||||
}
|
||||
return self::$db->lastId();
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/bugreport/plugin.php
|
||||
*
|
||||
* This houses all of the main plugin info and functionality.
|
||||
*
|
||||
* @package TP BugReports
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Plugins;
|
||||
|
||||
use ReflectionClass;
|
||||
use TheTempusProject\Classes\Installer;
|
||||
use TheTempusProject\Houdini\Classes\Navigation;
|
||||
use TheTempusProject\Classes\Plugin;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
|
||||
class Bugreport extends Plugin {
|
||||
public $pluginName = 'TP BugReports';
|
||||
public $pluginAuthor = 'JoeyK';
|
||||
public $pluginWebsite = 'https://TheTempusProject.com';
|
||||
public $modelVersion = '1.0';
|
||||
public $pluginVersion = '3.0';
|
||||
public $pluginDescription = '';
|
||||
public $configName = 'bugreports';
|
||||
public $configMatrix = [
|
||||
'enabled' => [
|
||||
'type' => 'radio',
|
||||
'pretty' => 'Enable Bug reporting.',
|
||||
'default' => true,
|
||||
],
|
||||
'sendEmail' => [
|
||||
'type' => 'radio',
|
||||
'pretty' => 'Email the user after submitting.',
|
||||
'default' => true,
|
||||
],
|
||||
'emailTemplate' => [
|
||||
'type' => 'text',
|
||||
'pretty' => 'Email Template',
|
||||
'default' => 'BugReportEmail',
|
||||
],
|
||||
];
|
||||
public $permissionMatrix = [
|
||||
'bugReport' => [
|
||||
'pretty' => 'Can Submit Bug Reports',
|
||||
'default' => false,
|
||||
],
|
||||
];
|
||||
public $contact_footer_links = [
|
||||
[
|
||||
'text' => 'Bug Report',
|
||||
'url' => '{ROOT_URL}bugreport',
|
||||
'filter' => 'loggedin',
|
||||
],
|
||||
];
|
||||
public $admin_links = [
|
||||
[
|
||||
'text' => '<i class="fa fa-fw fa-bug"></i> Bug Reports',
|
||||
'url' => '{ROOT_URL}admin/bugreport',
|
||||
],
|
||||
];
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
<div class="context-main-bg context-main p-3">
|
||||
<legend class="text-center">Bug Reports</legend>
|
||||
<hr>
|
||||
{ADMIN_BREADCRUMBS}
|
||||
<form action="{ROOT_URL}admin/bugreport/delete" method="post">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 5%">ID</th>
|
||||
<th style="width: 20%">Time</th>
|
||||
<th style="width: 60%">Description</th>
|
||||
<th style="width: 5%"></th>
|
||||
<th style="width: 5%"></th>
|
||||
<th style="width: 5%">
|
||||
<input type="checkbox" onchange="checkAll(this)" name="check.br" value="BR_[]">
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{LOOP}
|
||||
<tr>
|
||||
<td align="center">{ID}</td>
|
||||
<td align="center">{DTC}{time}{/DTC}</td>
|
||||
<td>{description}</td>
|
||||
<td><a href="{ROOT_URL}admin/bugreport/view/{ID}" class="btn btn-sm btn-primary"><i class="fa fa-fw fa-upload"></i></a></td>
|
||||
<td><a href="{ROOT_URL}admin/bugreport/delete/{ID}" class="btn btn-sm btn-danger"><i class="fa fa-fw fa-trash"></i></a></td>
|
||||
<td>
|
||||
<input type="checkbox" value="{ID}" name="BR_[]">
|
||||
</td>
|
||||
</tr>
|
||||
{/LOOP}
|
||||
{ALT}
|
||||
<tr>
|
||||
<td align="center" colspan="6">
|
||||
No results to show.
|
||||
</td>
|
||||
</tr>
|
||||
{/ALT}
|
||||
</tbody>
|
||||
</table>
|
||||
<button name="submit" value="submit" type="submit" class="btn btn-sm btn-danger"><i class="fa fa-fw fa-trash"></i></button>
|
||||
</form>
|
||||
<br>
|
||||
<a href="{ROOT_URL}admin/bugreport/clear">clear all</a>
|
||||
</div>
|
@ -1,69 +0,0 @@
|
||||
<div class="container py-4">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-8">
|
||||
{ADMIN_BREADCRUMBS}
|
||||
<div class="card shadow">
|
||||
<!-- Card Header -->
|
||||
<div class="card-header text-center bg-dark text-white">
|
||||
<h3 class="card-title mb-0">Bug Report</h3>
|
||||
</div>
|
||||
|
||||
<!-- Card Body -->
|
||||
<div class="card-body">
|
||||
<div class="row align-items-center">
|
||||
<!-- Log Details -->
|
||||
<table class="table table-borderless">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row">ID:</th>
|
||||
<td>{ID}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Time submitted</th>
|
||||
<td>{DTC}{time}{/DTC}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">URL:</th>
|
||||
<td><a href="{URL}">{URL}</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Original URL</th>
|
||||
<td><a href="{OURL}">{OURL}</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Multiple occurrences?</th>
|
||||
<td>{repeatText}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">IP:</th>
|
||||
<td>{ip}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">User:</th>
|
||||
<td><a href="{ROOT_URL}admin/users/view/{userID}">{submittedBy}</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row" colspan="2">Description:</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">{description}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Admin Controls -->
|
||||
<div class="card-footer text-center">
|
||||
{ADMIN}
|
||||
<form action="{ROOT_URL}admin/bugreport/delete" method="post">
|
||||
<input type="hidden" name="BR_" value="{ID}">
|
||||
<input type="hidden" name="token" value="{TOKEN}">
|
||||
<button name="submit" value="submit" type="submit" class="btn btn-sm btn-danger"><i class="fa fa-fw fa-trash"></i></button>
|
||||
</form>
|
||||
{/ADMIN}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -1,52 +0,0 @@
|
||||
<div class="col-8 mx-auto p-4 rounded shadow-sm mb-5 context-main-bg mt-4 container">
|
||||
<h2 class="text-center mb-4">Bug Report</h2>
|
||||
<hr>
|
||||
<p>Thank you for visiting our bug reporting page. We value our users' input highly and in an effort to better serve your needs, please fill out the form below to help us address this issue.</p>
|
||||
<p>We read each and every bug report submitted, and by submitting this form you allow us to send you a follow-up email.</p>
|
||||
<form action="" method="post">
|
||||
<!-- Page URL -->
|
||||
<div class="mb-3">
|
||||
<label for="url" class="form-label">Page you were trying to reach:</label>
|
||||
<input type="url" name="url" id="url" class="form-control" aria-describedby="urlHelp" required>
|
||||
<small id="urlHelp" class="form-text text-muted">
|
||||
What is the URL of the page you actually received the error on? (The URL is the website address. Example: {ROOT_URL}home)
|
||||
</small>
|
||||
</div>
|
||||
|
||||
<!-- Referrer URL -->
|
||||
<div class="mb-3">
|
||||
<label for="ourl" class="form-label">Page you were on:</label>
|
||||
<input type="url" name="ourl" id="ourl" class="form-control" aria-describedby="ourlHelp">
|
||||
<small id="ourlHelp" class="form-text text-muted">
|
||||
What is the URL of the page you were on before you received the error? (The URL is the website address. Example: {ROOT_URL}home/newhome)
|
||||
</small>
|
||||
</div>
|
||||
|
||||
<!-- Repeat Issue -->
|
||||
<div class="mb-3">
|
||||
<label class="form-label">*Has this happened more than once?</label>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="radio" name="repeat" id="repeatNo" value="false" checked>
|
||||
<label class="form-check-label" for="repeatNo">No</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="radio" name="repeat" id="repeatYes" value="true">
|
||||
<label class="form-check-label" for="repeatYes">Yes</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Description -->
|
||||
<div class="mb-3">
|
||||
<label for="entry" class="form-label">Describe the problem/error as best as you can: (max: 2000 characters)</label>
|
||||
<textarea class="form-control" name="entry" id="entry" rows="6" maxlength="2000" required></textarea>
|
||||
</div>
|
||||
|
||||
<!-- Hidden Token -->
|
||||
<input type="hidden" name="token" value="{TOKEN}">
|
||||
|
||||
<!-- Submit Button -->
|
||||
<div class="text-center">
|
||||
<button type="submit" name="submit" value="submit" class="btn btn-primary btn-lg">Submit</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
@ -1,83 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/comments/controllers/admin/comments.php
|
||||
*
|
||||
* This is the comments admin controller.
|
||||
*
|
||||
* @package TP Comments
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Controllers\Admin;
|
||||
|
||||
use TheTempusProject\Houdini\Classes\Navigation;
|
||||
use TheTempusProject\Houdini\Classes\Issues;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Houdini\Classes\Components;
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\Bedrock\Functions\Check;
|
||||
use TheTempusProject\Classes\Forms;
|
||||
use TheTempusProject\Classes\AdminController;
|
||||
use TheTempusProject\Models\Comments as CommentsModel;
|
||||
|
||||
class Comments extends AdminController {
|
||||
protected static $comments;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$title = 'Admin - Comments';
|
||||
self::$comments = new CommentsModel;
|
||||
$view = Navigation::activePageSelect( 'nav.admin', '/admin/comments' );
|
||||
Components::set( 'ADMINNAV', $view );
|
||||
}
|
||||
|
||||
public function edit( $data = null ) {
|
||||
if ( !Input::exists( 'submit' ) ) {
|
||||
return Views::view( 'comments.admin.edit', self::$comments->findById( $data ) );
|
||||
}
|
||||
if ( !Forms::check( 'editComment' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your request.' => Check::userErrors() ] );
|
||||
return Views::view( 'comments.admin.edit', self::$comments->findById( $data ) );
|
||||
}
|
||||
if ( self::$comments->update( $data, Input::post( 'comment' ) ) ) {
|
||||
Issues::add( 'success', 'Comment updated' );
|
||||
} else {
|
||||
return Views::view( 'comments.admin.edit', self::$comments->findById( $data ) );
|
||||
}
|
||||
$this->index();
|
||||
}
|
||||
|
||||
public function viewComments( $contentID = null ) {
|
||||
if ( empty( $contentID ) ) {
|
||||
Issues::add( 'error', 'Content ID not found.' );
|
||||
return $this->index();
|
||||
}
|
||||
$contentData = self::$comments->findById( $data );
|
||||
if ( empty( $contentID ) ) {
|
||||
return Views::view( 'comments.list', $commentData );
|
||||
}
|
||||
Issues::add( 'error', 'Comment not found.' );
|
||||
$this->index();
|
||||
}
|
||||
|
||||
public function delete( $data = null ) {
|
||||
if ( $data == null ) {
|
||||
if ( !Input::exists( 'C_' ) ) {
|
||||
return $this->index();
|
||||
}
|
||||
$data = Input::post( 'C_' );
|
||||
}
|
||||
if ( !self::$comments->delete( $data ) ) {
|
||||
Issues::add( 'error', 'There was an error with your request.' );
|
||||
} else {
|
||||
Issues::add( 'success', 'Comment has been deleted' );
|
||||
}
|
||||
$this->index();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
Views::view( 'comments.admin.list', self::$comments->recent() );
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/comments/controllers/moderator.php
|
||||
*
|
||||
* This is the Moderator controller.
|
||||
*
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Controllers;
|
||||
|
||||
use TheTempusProject\Houdini\Classes\Template;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Houdini\Classes\Issues;
|
||||
use TheTempusProject\Classes\Controller;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
use TheTempusProject\Hermes\Functions\Redirect;
|
||||
use TheTempusProject\Bedrock\Functions\Session;
|
||||
|
||||
class Moderator extends Controller {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
Template::noIndex();
|
||||
if ( !App::$isMod ) {
|
||||
Session::flash( 'error', 'You do not have permission to view this page.' );
|
||||
return Redirect::home();
|
||||
}
|
||||
}
|
||||
|
||||
public function index() {
|
||||
self::$title = 'Moderator\'s Area';
|
||||
Views::view( 'comments.moderator' );
|
||||
}
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
/**
|
||||
* Comments
|
||||
*/
|
||||
.comments {
|
||||
margin-top: 120px;
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/comments/forms.php
|
||||
*
|
||||
* This houses all of the form checking functions for this plugin.
|
||||
*
|
||||
* @package TP Comments
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Plugins\Comments;
|
||||
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\Bedrock\Functions\Check;
|
||||
use TheTempusProject\Classes\Forms;
|
||||
|
||||
class CommentsForms extends Forms {
|
||||
/**
|
||||
* Adds these functions to the form list.
|
||||
*/
|
||||
public function __construct() {
|
||||
self::addHandler( 'newComment', __CLASS__, 'newComment' );
|
||||
self::addHandler( 'editComment', __CLASS__, 'editComment' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the new comment form.
|
||||
*
|
||||
* @return {bool}
|
||||
*/
|
||||
public static function newComment() {
|
||||
if ( !Input::exists( 'comment' ) ) {
|
||||
Check::addUserError( 'You cannot post a blank comment.' );
|
||||
return false;
|
||||
}
|
||||
if ( !Input::exists( 'contentId' ) ) {
|
||||
Check::addUserError( 'Content ID was missing.' );
|
||||
return false;
|
||||
}
|
||||
// these are disabled because i need to figure out a solution for pages where images are wrong
|
||||
// a missing image loads a new token and messes this up
|
||||
// if ( !Check::token() ) {
|
||||
// return false;
|
||||
// }
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the edit comment form.
|
||||
*
|
||||
* @return {bool}
|
||||
*/
|
||||
public static function editComment() {
|
||||
if ( !Input::exists( 'comment' ) ) {
|
||||
Check::addUserError( 'You cannot post a blank comment.' );
|
||||
return false;
|
||||
}
|
||||
// these are disabled because i need to figure out a solution for pages where images are wrong
|
||||
// a missing image loads a new token and messes this up
|
||||
// if ( !Check::token() ) {
|
||||
// return false;
|
||||
// }
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
new CommentsForms;
|
@ -1,184 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/comments/models/comment.php
|
||||
*
|
||||
* This class is used for the creation, retrieval, and manipulation
|
||||
* of the comments table.
|
||||
*
|
||||
* @package TP Comments
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Models;
|
||||
|
||||
use TheTempusProject\Bedrock\Functions\Check;
|
||||
use TheTempusProject\Canary\Bin\Canary as Debug;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Classes\DatabaseModel;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
use TheTempusProject\Canary\Classes\CustomException;
|
||||
use TheTempusProject\Houdini\Classes\Filters;
|
||||
|
||||
class Comments extends DatabaseModel {
|
||||
public $tableName = 'comments';
|
||||
public $databaseMatrix = [
|
||||
[ 'author', 'int', '11' ],
|
||||
[ 'contentID', 'int', '11' ],
|
||||
[ 'created', 'int', '10' ],
|
||||
[ 'edited', 'int', '10' ],
|
||||
[ 'approved', 'int', '1' ],
|
||||
[ 'contentType', 'varchar', '32' ],
|
||||
[ 'content', 'text', '' ],
|
||||
];
|
||||
|
||||
public function count( $contentType, $contentID ) {
|
||||
if ( !Check::id( $contentID ) ) {
|
||||
Debug::info( 'Comments: illegal ID.' );
|
||||
|
||||
return false;
|
||||
}
|
||||
if ( !Check::dataTitle( $contentType ) ) {
|
||||
Debug::info( 'Comments: illegal Type.' );
|
||||
|
||||
return false;
|
||||
}
|
||||
$where = ['contentType', '=', $contentType, 'AND', 'contentID', '=', $contentID];
|
||||
$data = self::$db->get( $this->tableName, $where );
|
||||
if ( !$data->count() ) {
|
||||
Debug::info( 'No comments found.' );
|
||||
|
||||
return 0;
|
||||
}
|
||||
return $data->count();
|
||||
}
|
||||
|
||||
public function display( $displayCount, $contentType, $contentID ) {
|
||||
if ( !Check::id( $contentID ) ) {
|
||||
Debug::info( 'Comments: illegal ID.' );
|
||||
|
||||
return false;
|
||||
}
|
||||
if ( !Check::dataTitle( $contentType ) ) {
|
||||
Debug::info( 'Comments: illegal Type.' );
|
||||
|
||||
return false;
|
||||
}
|
||||
$where = ['contentType', '=', $contentType, 'AND', 'contentID', '=', $contentID];
|
||||
$commentData = self::$db->get( $this->tableName, $where, 'created', 'DESC', [0, $displayCount] );
|
||||
if ( !$commentData->count() ) {
|
||||
Debug::info( 'No comments found.' );
|
||||
|
||||
return false;
|
||||
}
|
||||
return $this->filter( $commentData->results() );
|
||||
}
|
||||
|
||||
public function update( $id, $comment ) {
|
||||
if ( empty( self::$log ) ) {
|
||||
self::$log = new Log;
|
||||
}
|
||||
if ( !Check::id( $id ) ) {
|
||||
Debug::info( 'Comments: illegal ID.' );
|
||||
|
||||
return false;
|
||||
}
|
||||
$fields = [
|
||||
'edited' => time(),
|
||||
'content' => $comment,
|
||||
'approved' => 1,
|
||||
];
|
||||
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
|
||||
new CustomException( 'commentUpdate' );
|
||||
Debug::error( "Post: $id not updated: $fields" );
|
||||
|
||||
return false;
|
||||
}
|
||||
self::$log->admin( "Updated Comment: $id" );
|
||||
return true;
|
||||
}
|
||||
|
||||
public function create( $contentType, $contentID, $comment ) {
|
||||
if ( !Check::id( $contentID ) ) {
|
||||
Debug::info( 'Comments: illegal ID.' );
|
||||
|
||||
return false;
|
||||
}
|
||||
if ( !Check::dataTitle( $contentType ) ) {
|
||||
Debug::info( 'Comments: illegal Type.' );
|
||||
|
||||
return false;
|
||||
}
|
||||
$fields = [
|
||||
'author' => App::$activeUser->ID,
|
||||
'edited' => time(),
|
||||
'created' => time(),
|
||||
'content' => $comment,
|
||||
'contentType' => $contentType,
|
||||
'contentID' => $contentID,
|
||||
'approved' => 0,
|
||||
];
|
||||
if ( !self::$db->insert( $this->tableName, $fields ) ) {
|
||||
new CustomException( 'commentCreate' );
|
||||
Debug::error( "Comments: $data not created: $fields" );
|
||||
|
||||
return false;
|
||||
}
|
||||
return self::$db->lastId();
|
||||
}
|
||||
|
||||
public function filter( $data, $params = [] ) {
|
||||
foreach ( $data as $instance ) {
|
||||
if ( !is_object( $instance ) ) {
|
||||
$instance = $data;
|
||||
$end = true;
|
||||
}
|
||||
if ( App::$isAdmin || ( App::$isLoggedIn && $instance->author == App::$activeUser->ID ) ) {
|
||||
$instance->commentControl = Views::simpleView( 'comments.control', ['ID' => $instance->ID] );
|
||||
} else {
|
||||
$instance->commentControl = '';
|
||||
}
|
||||
$data = self::$db->get( $instance->contentType, ['ID', '=', $instance->contentID] )->results();
|
||||
if ( empty( $data ) ) {
|
||||
$title = 'Unknown';
|
||||
} elseif ( empty( $data[0]->title ) ) {
|
||||
$title = 'Unknown';
|
||||
} else {
|
||||
$title = $data[0]->title;
|
||||
}
|
||||
$authorName = self::$user->getUsername( $instance->author );
|
||||
$authorAvatar = self::$user->getAvatar( $instance->author );
|
||||
$instance->avatar = $authorAvatar;
|
||||
$instance->authorName = $authorName;
|
||||
$instance->contentTitle = $title;
|
||||
$instance->content = Filters::applyOne( 'mentions.0', $instance->content, true );
|
||||
$instance->content = Filters::applyOne( 'hashtags.0', $instance->content, true );
|
||||
$out[] = $instance;
|
||||
if ( !empty( $end ) ) {
|
||||
$out = $out[0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
public function recent( $contentType = 'all', $limit = null ) {
|
||||
if ( $contentType === 'all' ) {
|
||||
$where = ['ID', '>', '0'];
|
||||
} else {
|
||||
$where = ['contentType', '=', $contentType];
|
||||
}
|
||||
if ( empty( $limit ) ) {
|
||||
$commentData = self::$db->get( $this->tableName, $where, 'created', 'DESC' );
|
||||
} else {
|
||||
$commentData = self::$db->get( $this->tableName, $where, 'created', 'DESC', [0, $limit] );
|
||||
}
|
||||
if ( !$commentData->count() ) {
|
||||
Debug::info( 'No comments found.' );
|
||||
|
||||
return false;
|
||||
}
|
||||
return $this->filter( $commentData->results() );
|
||||
}
|
||||
}
|
@ -1,154 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/comments/plugin.php
|
||||
*
|
||||
* This houses all of the main plugin info and functionality.
|
||||
*
|
||||
* @package TP Comments
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Plugins;
|
||||
|
||||
use ReflectionClass;
|
||||
use TheTempusProject\Bedrock\Functions\Check;
|
||||
use TheTempusProject\Classes\Installer;
|
||||
use TheTempusProject\Houdini\Classes\Navigation;
|
||||
use TheTempusProject\Classes\Plugin;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\Houdini\Classes\Components;
|
||||
use TheTempusProject\Houdini\Classes\Issues;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Classes\Forms;
|
||||
use TheTempusProject\Hermes\Functions\Redirect;
|
||||
use TheTempusProject\Bedrock\Functions\Session;
|
||||
use TheTempusProject\Models\Comments as CommentsModel;
|
||||
|
||||
class Comments extends Plugin {
|
||||
protected static $comments;
|
||||
public $pluginName = 'TP Comments';
|
||||
public $pluginAuthor = 'JoeyK';
|
||||
public $pluginWebsite = 'https://TheTempusProject.com';
|
||||
public $modelVersion = '1.0';
|
||||
public $pluginVersion = '3.0';
|
||||
public $pluginDescription = 'A simple plugin to add user comments for other plugins.';
|
||||
public $admin_links = [
|
||||
[
|
||||
'text' => '<i class="fa fa-fw fa-comment"></i> Comments',
|
||||
'url' => '{ROOT_URL}admin/comments',
|
||||
],
|
||||
];
|
||||
public $main_links = [
|
||||
[
|
||||
'text' => 'Moderator',
|
||||
'url' => '{ROOT_URL}moderator/index',
|
||||
'filter' => 'mod',
|
||||
]
|
||||
];
|
||||
public $permissionMatrix = [
|
||||
'modAccess' => [
|
||||
'pretty' => 'Access Moderator Areas',
|
||||
'default' => false,
|
||||
],
|
||||
];
|
||||
public $resourceMatrix = [
|
||||
'groups' => [
|
||||
[
|
||||
'name' => 'Moderator',
|
||||
'permissions' => '{"adminAccess":false}',
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
public function __construct( $load = false ) {
|
||||
if ( !empty(App::$activePerms) ) {
|
||||
App::$isMod = !empty(App::$activePerms['modAccess']);
|
||||
} else {
|
||||
App::$isMod = false;
|
||||
}
|
||||
$this->filters[] = [
|
||||
'name' => 'mod',
|
||||
'find' => '#{MOD}(.*?){/MOD}#is',
|
||||
'replace' => ( App::$isMod ? '$1' : '' ),
|
||||
'enabled' => true,
|
||||
];
|
||||
self::$comments = new CommentsModel;
|
||||
parent::__construct( $load );
|
||||
}
|
||||
|
||||
public function formPost( $type, $content, $redirect ) {
|
||||
if ( ! $this->checkEnabled() ) {
|
||||
Debug::info( 'Comments Plugin is disabled in the control panel.' );
|
||||
Issues::add( 'error', 'Comments are disabled.' );
|
||||
return false;
|
||||
}
|
||||
if ( !App::$isLoggedIn ) {
|
||||
Session::flash( 'notice', 'You must be logged in to post comments.' );
|
||||
return Redirect::to( $redirect . $content->ID );
|
||||
}
|
||||
if ( !Forms::check( 'newComment' ) ) {
|
||||
Session::flash( 'error', [ 'There was a problem with your comment form.' => Check::userErrors() ] );
|
||||
return Redirect::to( $redirect . $content->ID );
|
||||
}
|
||||
if ( !self::$comments->create( $type, $content->ID, Input::post( 'comment' ) ) ) {
|
||||
Session::flash( 'error', [ 'There was a problem posting your comment.' => Check::userErrors() ] );
|
||||
} else {
|
||||
Session::flash( 'success', 'Comment posted' );
|
||||
}
|
||||
return Redirect::to( $redirect . $content->ID );
|
||||
}
|
||||
|
||||
public function formEdit( $type, $content, $redirect ) {
|
||||
if ( ! $this->checkEnabled() ) {
|
||||
Debug::info( 'Comments Plugin is disabled in the control panel.' );
|
||||
Issues::add( 'error', 'Comments are disabled.' );
|
||||
return false;
|
||||
}
|
||||
if ( !App::$isLoggedIn ) {
|
||||
Session::flash( 'notice', 'You must be logged in to do that.' );
|
||||
return Redirect::to( $type );
|
||||
}
|
||||
if ( !App::$isAdmin && $content->author != App::$activeUser->ID ) {
|
||||
Session::flash( 'error', 'You do not have permission to edit this comment' );
|
||||
return Redirect::to( $type );
|
||||
}
|
||||
if ( !Input::exists( 'submit' ) ) {
|
||||
return Views::view( 'comments.admin.edit', $content );
|
||||
}
|
||||
if ( !Forms::check( 'editComment' ) ) {
|
||||
Issues::add( 'error', [ 'There was a problem editing your comment.' => Check::userErrors() ] );
|
||||
return Views::view( 'comments.admin.edit', $content );
|
||||
}
|
||||
if ( !self::$comments->update( $content->ID, Input::post( 'comment' ) ) ) {
|
||||
Issues::add( 'error', [ 'There was a problem editing your comment.' => Check::userErrors() ] );
|
||||
return Views::view( 'comments.admin.edit', $content );
|
||||
}
|
||||
Session::flash( 'success', 'Comment updated' );
|
||||
return Redirect::to( $redirect . $content->contentID );
|
||||
}
|
||||
|
||||
public function formDelete( $type, $content, $redirect ) {
|
||||
if ( ! $this->checkEnabled() ) {
|
||||
Debug::info( 'Comments Plugin is disabled in the control panel.' );
|
||||
Issues::add( 'error', 'Comments are disabled.' );
|
||||
return false;
|
||||
}
|
||||
if ( !App::$isLoggedIn ) {
|
||||
Session::flash( 'notice', 'You must be logged in to do that.' );
|
||||
return Redirect::to( $type );
|
||||
}
|
||||
if ( !App::$isAdmin && $content->author != App::$activeUser->ID ) {
|
||||
Session::flash( 'error', 'You do not have permission to edit this comment' );
|
||||
return Redirect::to( $type );
|
||||
}
|
||||
if ( !self::$comments->delete( (array) $content->ID ) ) {
|
||||
Session::flash( 'error', 'There was an error with your request.' );
|
||||
} else {
|
||||
Session::flash( 'success', 'Comment has been deleted' );
|
||||
}
|
||||
return Redirect::to( $redirect . $content->contentID );
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
<legend>New Comments</legend>
|
||||
<table class="table context-main">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 20%"></th>
|
||||
<th style="width: 70%"></th>
|
||||
<th style="width: 5%"></th>
|
||||
<th style="width: 5%"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{LOOP}
|
||||
<tr>
|
||||
<td>{authorName}</td>
|
||||
<td>{content}</td>
|
||||
<td><a href="{ROOT_URL}admin/comments/edit/{ID}" class="btn btn-sm btn-warning"><i class="fa fa-fw fa-pencil"></i></a></td>
|
||||
<td><a href="{ROOT_URL}admin/comments/delete/{ID}" class="btn btn-sm btn-danger"><i class="fa fa-fw fa-trash"></i></a></td>
|
||||
</tr>
|
||||
{/LOOP}
|
||||
{ALT}
|
||||
<tr>
|
||||
<td align="center" colspan="4">
|
||||
No results to show.
|
||||
</td>
|
||||
</tr>
|
||||
{/ALT}
|
||||
</tbody>
|
||||
</table>
|
@ -1,25 +0,0 @@
|
||||
<div class="mb-4 mt-4">
|
||||
<div class="offset-md-1 col-10 p-3 context-main-bg">
|
||||
<legend class="text-center">Edit Comment</legend>
|
||||
<hr>
|
||||
{ADMIN_BREADCRUMBS}
|
||||
<form action="" method="post" class="container py-4">
|
||||
<fieldset>
|
||||
<div class="mb-3 row">
|
||||
<label for="comment" class="col-lg-5 col-form-label text-end">Comment:</label>
|
||||
<div class="col-lg-3">
|
||||
<textarea class="form-control" name="comment" maxlength="2000" rows="5" cols="50" id="comment">{content}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Hidden Token -->
|
||||
<input type="hidden" name="token" value="{TOKEN}">
|
||||
|
||||
<!-- Submit Button -->
|
||||
<div class="text-center">
|
||||
<button type="submit" name="submit" value="submit" class="btn btn-primary btn-lg">Save</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
@ -1,45 +0,0 @@
|
||||
<div class="context-main-bg context-main p-3">
|
||||
<legend class="text-center">Recent Comments</legend>
|
||||
<hr>
|
||||
{ADMIN_BREADCRUMBS}
|
||||
<form action="{ROOT_URL}admin/comments/delete" method="post">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 20%">Author</th>
|
||||
<th style="width: 20%">Subject</th>
|
||||
<th style="width: 35%">Comment</th>
|
||||
<th style="width: 10%">Time</th>
|
||||
<th style="width: 5%"></th>
|
||||
<th style="width: 5%"></th>
|
||||
<th style="width: 5%">
|
||||
<input type="checkbox" onchange="checkAll(this)" name="check.c" value="C_[]">
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{LOOP}
|
||||
<tr>
|
||||
<td><a href="{ROOT_URL}admin/users/view/{author}">{authorName}</a></td>
|
||||
<td><a href="{ROOT_URL}admin/blog/view/{contentID}">{contentTitle}</a></td>
|
||||
<td>{content}</td>
|
||||
<td>{DTC}{created}{/DTC}</td>
|
||||
<td><a href="{ROOT_URL}admin/comments/edit/{ID}" class="btn btn-sm btn-warning"><i class="fa fa-fw fa-pencil"></i></a></td>
|
||||
<td><a href="{ROOT_URL}admin/comments/delete/{ID}" class="btn btn-sm btn-danger"><i class="fa fa-fw fa-trash"></i></a></td>
|
||||
<td>
|
||||
<input type="checkbox" value="{ID}" name="C_[]">
|
||||
</td>
|
||||
</tr>
|
||||
{/LOOP}
|
||||
{ALT}
|
||||
<tr>
|
||||
<td align="center" colspan="7">
|
||||
No results to show.
|
||||
</td>
|
||||
</tr>
|
||||
{/ALT}
|
||||
</tbody>
|
||||
</table>
|
||||
<button name="submit" value="submit" type="submit" class="btn btn-sm btn-danger"><i class="fa fa-fw fa-trash"></i></button>
|
||||
</form>
|
||||
</div>
|
@ -1,8 +0,0 @@
|
||||
<div class="action">
|
||||
<a href="{ROOT_URL}{COMMENT_TYPE}/comments/edit/{ID}" class="btn btn-warning btn-sm">
|
||||
<span class="fa fa-fw fa-pencil"></span>
|
||||
</a>
|
||||
<a href="{ROOT_URL}{COMMENT_TYPE}/comments/delete/{ID}" class="btn btn-danger btn-sm">
|
||||
<span class="fa fa-fw fa-trash"></span>
|
||||
</a>
|
||||
</div>
|
@ -1,14 +0,0 @@
|
||||
<form action="" method="post" class="text-center mx-auto mt-4" style="max-width: 600px;">
|
||||
<div class="mb-3">
|
||||
<textarea
|
||||
class="form-control"
|
||||
name="comment"
|
||||
maxlength="2000"
|
||||
rows="4"
|
||||
id="comment"
|
||||
placeholder="Write your comment here..."></textarea>
|
||||
</div>
|
||||
<button name="submit" value="submit" type="submit" class="btn btn-lg btn-primary mb-3">Comment</button>
|
||||
<input type="hidden" name="token" value="{TOKEN}">
|
||||
<input type="hidden" name="contentId" value="{CONTENT_ID}">
|
||||
</form>
|
@ -1,39 +0,0 @@
|
||||
<div class="card">
|
||||
<div class="card-header d-flex align-items-center justify-content-between context-second-bg context-main">
|
||||
<h3 class="card-title mb-0">
|
||||
<i class="fa fa-fw fa-comment"></i> Comments
|
||||
</h3>
|
||||
<span class="badge bg-primary">{count}</span>
|
||||
</div>
|
||||
<div class="card-body context-main-bg context-main">
|
||||
<ul class="list-group list-group-flush">
|
||||
{LOOP}
|
||||
<li class="list-group-item context-second-bg context-main mb-2">
|
||||
<div class="d-flex align-items-start">
|
||||
<div class="me-3">
|
||||
<img src="{ROOT_URL}{avatar}" class="rounded-circle" alt="User Avatar" style="width: 50px; height: 50px;">
|
||||
</div>
|
||||
<div>
|
||||
<div class="mb-1">
|
||||
<small class="text-muted">
|
||||
By: <a href="{ROOT_URL}home/profile/{author}" class="text-decoration-none">{authorName}</a> on {DTC date}{created}{/DTC}
|
||||
</small>
|
||||
</div>
|
||||
<div class="comment-text">
|
||||
{content}
|
||||
</div>
|
||||
{commentControl}
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
{/LOOP}
|
||||
{ALT}
|
||||
<li class="list-group-item context-second-bg context-main mb-2">
|
||||
<div class="text-center">
|
||||
<p class="mb-0">Be the first to comment.</p>
|
||||
</div>
|
||||
</li>
|
||||
{/ALT}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
@ -1,7 +0,0 @@
|
||||
<h1>Moderator' Area</h1>
|
||||
<div class="jumbotron">
|
||||
<h1>Welcome!</h1>
|
||||
<p>This is the moderator section. You can give some groups permission to access this area. The menu is hidden for normal users and if they get a link to a moderator's area, the authentication system will stop them from accessing any content protected this way.</p>
|
||||
<p>You can even use this feature in-line with your views, hiding certain components from non-moderators</p>
|
||||
<p>The idea behind this role is for them to help you in policing comments as needed.</p>
|
||||
</div>
|
@ -1,121 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* app/controllers/messages.php
|
||||
*
|
||||
* This is the user messages controller.
|
||||
*
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Controllers;
|
||||
|
||||
use TheTempusProject\Classes\Controller;
|
||||
use TheTempusProject\Classes\Forms as FormChecker;
|
||||
use TheTempusProject\Models\Message;
|
||||
use TheTempusProject\Houdini\Classes\Components;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Houdini\Classes\Issues;
|
||||
use TheTempusProject\Bedrock\Functions\Check;
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
use TheTempusProject\Hermes\Functions\Redirect;
|
||||
use TheTempusProject\Bedrock\Functions\Session;
|
||||
|
||||
class Messages extends Controller {
|
||||
private static $message;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$title = 'Messages';
|
||||
self::$message = new Message;
|
||||
if ( ! App::$isLoggedIn ) {
|
||||
Session::flash( 'error', 'You do not have permission to access this page.' );
|
||||
return Redirect::home();
|
||||
}
|
||||
}
|
||||
|
||||
public function create() {
|
||||
self::$title .= ' - New Message';
|
||||
if ( Input::get( 'prepopuser' ) ) {
|
||||
$data = Input::get( 'prepopuser' );
|
||||
}
|
||||
if ( !empty( $data ) && self::$user->checkUsername( $data ) ) {
|
||||
Components::set( 'prepopuser', $data );
|
||||
} else {
|
||||
Components::set( 'prepopuser', '' );
|
||||
}
|
||||
if ( !Input::exists( 'submit' ) ) {
|
||||
return Views::view( 'messages.create' );
|
||||
}
|
||||
if ( !FormChecker::check( 'newMessage' ) ) {
|
||||
Issues::add( 'error', [ 'There was an problem sending your messages.' => Check::userErrors() ] );
|
||||
return Views::view( 'messages.create' );
|
||||
}
|
||||
if ( self::$message->newThread( Input::post( 'toUser' ), Input::post( 'subject' ), Input::post( 'message' ) ) ) {
|
||||
Issues::add( 'success', 'Message Sent.' );
|
||||
} else {
|
||||
Issues::add( 'notice', 'There was an problem sending your messages.' );
|
||||
}
|
||||
return $this->index();
|
||||
}
|
||||
|
||||
public function delete( $id = '' ) {
|
||||
if ( Input::exists( 'T_' ) ) {
|
||||
self::$message->delete( Input::post( 'T_' ) );
|
||||
}
|
||||
if ( Input::exists( 'F_' ) ) {
|
||||
self::$message->delete( Input::post( 'F_' ) );
|
||||
}
|
||||
if ( Input::exists( 'ID' ) ) {
|
||||
self::$message->delete( Input::get( 'ID' ) );
|
||||
}
|
||||
if ( !empty( $id ) ) {
|
||||
self::$message->delete( $id );
|
||||
}
|
||||
return $this->index();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
Components::set( 'message_inbox', Views::simpleView( 'messages.inbox', self::$message->getInbox() ) );
|
||||
Components::set( 'message_outbox', Views::simpleView( 'messages.outbox', self::$message->getOutbox() ) );
|
||||
Views::view( 'messages.index' );
|
||||
}
|
||||
|
||||
public function read( $id = '' ) {
|
||||
self::$message->markRead( $id );
|
||||
return $this->index();
|
||||
}
|
||||
|
||||
public function reply() {
|
||||
if ( Input::exists( 'messageID' ) ) {
|
||||
$data = Input::post( 'messageID' );
|
||||
}
|
||||
if ( !Check::id( $data ) ) {
|
||||
Issues::add( 'error', 'There was an error with your request.' );
|
||||
return $this->index();
|
||||
}
|
||||
self::$title .= ' - Reply to: ' . self::$message->messageTitle( $data );
|
||||
if ( !Input::exists( 'message' ) ) {
|
||||
Components::set( 'messageID', $data );
|
||||
return Views::view( 'messages.reply' );
|
||||
}
|
||||
if ( !FormChecker::check( 'replyMessage' ) ) {
|
||||
Issues::add( 'error', [ 'There was an problem sending your messages.' => Check::userErrors() ] );
|
||||
Components::set( 'messageID', $data );
|
||||
return Views::view( 'messages.reply' );
|
||||
}
|
||||
if ( !self::$message->newMessageReply( $data, Input::post( 'message' ) ) ) {
|
||||
Issues::add( 'error', 'There was an error with your request.' );
|
||||
return $this->index();
|
||||
}
|
||||
Issues::add( 'success', 'Reply Sent.' );
|
||||
return $this->index();
|
||||
}
|
||||
|
||||
public function view( $id = '' ) {
|
||||
self::$title = self::$message->messageTitle( $id );
|
||||
return Views::view( 'messages.message', self::$message->getThread( $id, true ) );
|
||||
}
|
||||
}
|
@ -1,452 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* app/models/message.php
|
||||
*
|
||||
* Houses all of the functions for the core messaging system.
|
||||
*
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Models;
|
||||
|
||||
use TheTempusProject\Classes\DatabaseModel;
|
||||
use TheTempusProject\Houdini\Classes\Components;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Canary\Bin\Canary as Debug;
|
||||
use TheTempusProject\Bedrock\Functions\Check;
|
||||
use TheTempusProject\Bedrock\Functions\Sanitize;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
use TheTempusProject\Canary\Classes\CustomException;
|
||||
|
||||
class Message extends DatabaseModel {
|
||||
public $tableName = 'messages';
|
||||
public $databaseMatrix = [
|
||||
[ 'userTo', 'int', '11' ],
|
||||
[ 'userFrom', 'int', '11' ],
|
||||
[ 'parent', 'int', '11' ],
|
||||
[ 'sent', 'int', '10' ],
|
||||
[ 'lastReply', 'int', '10' ],
|
||||
[ 'senderDeleted', 'int', '1' ],
|
||||
[ 'recieverDeleted', 'int', '1' ],
|
||||
[ 'isRead', 'int', '1' ],
|
||||
[ 'message', 'text', '' ],
|
||||
[ 'subject', 'text', '' ],
|
||||
];
|
||||
private $messages;
|
||||
private $usernames;
|
||||
|
||||
/**
|
||||
* The model constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$message = $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the most recent relative message in a thread
|
||||
*
|
||||
* @param int $parent - the id of the parent message
|
||||
* @param string $user - the id of the relative user
|
||||
* @return object
|
||||
*/
|
||||
public function getLatestMessage( $parent, $user, $type = null ) {
|
||||
if ( !Check::id( $parent ) ) {
|
||||
Debug::info( 'Invalid message ID' );
|
||||
return false;
|
||||
}
|
||||
if ( !Check::id( $user ) ) {
|
||||
Debug::info( 'Invalid user ID' );
|
||||
return false;
|
||||
}
|
||||
$messageData = self::$db->get( $this->tableName, [ 'ID', '=', $parent ] );
|
||||
if ( $messageData->count() == 0 ) {
|
||||
Debug::info( 'Message not found.' );
|
||||
return false;
|
||||
}
|
||||
$message = $messageData->first();
|
||||
$params = [ 'parent', '=', $parent ];
|
||||
if ( $type !== null ) {
|
||||
$params = array_merge( $params, [ 'AND', $type, '=', $user ] );
|
||||
}
|
||||
$messageData = self::$db->get( $this->tableName, $params, 'ID', 'DESC', [ 0, 1 ] );
|
||||
if ( $messageData->count() != 0 ) {
|
||||
if ( $messageData->first()->recieverDeleted == 0 ) {
|
||||
$message = $messageData->first();
|
||||
} else {
|
||||
$message->recieverDeleted = 1;
|
||||
}
|
||||
}
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* This calls a view of the requested message.
|
||||
*
|
||||
* @param int $ID - The message ID you are looking for.
|
||||
* @return null
|
||||
*/
|
||||
public function getThread( $id, $markRead = false ) {
|
||||
if ( !Check::id( $id ) ) {
|
||||
Debug::info( 'Invalid ID' );
|
||||
return false;
|
||||
}
|
||||
$messageData = self::$db->get( $this->tableName, [ 'ID', '=', $id ] );
|
||||
if ( $messageData->count() == 0 ) {
|
||||
Debug::info( 'Message not found.' );
|
||||
return false;
|
||||
}
|
||||
$message = $messageData->first();
|
||||
if ( $message->userTo == App::$activeUser->ID ) {
|
||||
$permissionCheck = 1;
|
||||
if ( $message->recieverDeleted == 1 ) {
|
||||
Debug::info( 'User has already deleted this message.' );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ( $message->userFrom == App::$activeUser->ID ) {
|
||||
$permissionCheck = 1;
|
||||
if ( $message->senderDeleted == 1 ) {
|
||||
Debug::info( 'User has already deleted this message.' );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ( empty( $permissionCheck ) ) {
|
||||
Debug::info( 'You do not have permission to view this message.' );
|
||||
return false;
|
||||
}
|
||||
if ( $message->parent != 0 ) {
|
||||
$find = $message->parent;
|
||||
} else {
|
||||
$find = $message->ID;
|
||||
}
|
||||
$messageData = self::$db->get( $this->tableName, [ 'ID', '=', $find, 'OR', 'Parent', '=', $find ], 'ID', 'ASC' )->results();
|
||||
Components::set( 'PID', $find );
|
||||
|
||||
if ( $markRead == true ) {
|
||||
foreach ( $messageData as $instance ) {
|
||||
$this->markRead( $instance->ID );
|
||||
}
|
||||
}
|
||||
return $this->filter( $messageData );
|
||||
}
|
||||
|
||||
public function getInbox( $limit = null ) {
|
||||
if ( empty( $limit ) ) {
|
||||
$limit = 10;
|
||||
}
|
||||
$limit = [ 0, $limit ];
|
||||
$messageData = self::$db->get(
|
||||
$this->tableName,
|
||||
[
|
||||
'parent', '=', 0,
|
||||
'AND',
|
||||
'userFrom', '=', App::$activeUser->ID,
|
||||
'OR',
|
||||
'parent', '=', 0,
|
||||
'AND',
|
||||
'userTo', '=', App::$activeUser->ID,
|
||||
],
|
||||
'ID',
|
||||
'DESC',
|
||||
$limit
|
||||
);
|
||||
if ( $messageData->count() == 0 ) {
|
||||
Debug::info( 'getInbox: No messages found' );
|
||||
return false;
|
||||
}
|
||||
$filters = [
|
||||
'importantUser' => App::$activeUser->ID,
|
||||
'deleted' => false,
|
||||
'type' => 'userTo',
|
||||
];
|
||||
return $this->filter( $messageData->results(), $filters );
|
||||
}
|
||||
|
||||
/**
|
||||
* This function calls the view for the message outbox.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function getOutbox( $limit = null ) {
|
||||
if ( empty( $limit ) ) {
|
||||
$limit = 10;
|
||||
}
|
||||
$limit = [ 0, $limit ];
|
||||
$messageData = self::$db->get(
|
||||
$this->tableName,
|
||||
[
|
||||
'parent', '=', 0,
|
||||
'AND',
|
||||
'userFrom', '=', App::$activeUser->ID,
|
||||
],
|
||||
'ID',
|
||||
'DESC',
|
||||
$limit
|
||||
);
|
||||
if ( $messageData->count() == 0 ) {
|
||||
Debug::info( 'getOutbox: No messages found' );
|
||||
return false;
|
||||
}
|
||||
$filters = [
|
||||
'importantUser' => App::$activeUser->ID,
|
||||
'deleted' => false,
|
||||
'type' => 'userFrom',
|
||||
];
|
||||
return $this->filter( $messageData->results(), $filters );
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is to prep our messages for display. An array of raw messages
|
||||
* sent through this function will automatically have all the user ID's filter
|
||||
* into actual usernames.
|
||||
*
|
||||
* @param $messageArray - This is an array of messages that need to be processed.
|
||||
* @return array - It will return the same message array after being processed.
|
||||
* @todo add filtering for BB-code.
|
||||
*/
|
||||
public function filter( $messageArray, $filters = [] ) {
|
||||
$out = [];
|
||||
foreach ( $messageArray as $message ) {
|
||||
if ( !is_object( $message ) ) {
|
||||
$message = $messageArray;
|
||||
$end = true;
|
||||
}
|
||||
if ( isset( $filters['type'] ) && isset( $filters['importantUser'] ) ) {
|
||||
$type = $filters['type'];
|
||||
} else {
|
||||
$type = null;
|
||||
}
|
||||
if ( isset( $filters['importantUser'] ) ) {
|
||||
$user = $filters['importantUser'];
|
||||
} else {
|
||||
$user = App::$activeUser->ID;
|
||||
}
|
||||
if ( $message->parent == 0 ) {
|
||||
$last = $this->getLatestMessage( $message->ID, $user, $type );
|
||||
} else {
|
||||
$last = $message;
|
||||
}
|
||||
if ( $type != null && $message->$type != $user && $last->$type != $user ) {
|
||||
continue;
|
||||
}
|
||||
if ( isset( $filters['deleted'] ) && $filters['deleted'] == false ) {
|
||||
if ( $type == 'userFrom' ) {
|
||||
if ( $last->senderDeleted == 1 ) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if ( $type == 'userTo' ) {
|
||||
if ( $last->recieverDeleted == 1 ) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
$messageOut = (array) $message;
|
||||
$short = explode( ' ', Sanitize::contentShort( $message->message ) );
|
||||
$summary = implode( ' ', array_splice( $short, 0, 25 ) );
|
||||
if ( count( $short, 1 ) >= 25 ) {
|
||||
$messageOut['summary'] = $summary . '...';
|
||||
} else {
|
||||
$messageOut['summary'] = $summary;
|
||||
}
|
||||
if ( $last->isRead == 0 ) {
|
||||
$messageOut['unreadBadge'] = Views::simpleView( 'messages.unreadBadge' );
|
||||
} else {
|
||||
$messageOut['unreadBadge'] = '';
|
||||
}
|
||||
$messageOut['fromAvatar'] = self::$user->getAvatar( $message->userFrom );
|
||||
$messageOut['userTo'] = self::$user->getUsername( $message->userTo );
|
||||
$messageOut['userFrom'] = self::$user->getUsername( $message->userFrom );
|
||||
$out[] = (object) $messageOut;
|
||||
if ( !empty( $end ) ) {
|
||||
$out = $out[0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to check input and save messages to the DB.
|
||||
*
|
||||
* @param string $data - Username of the person receiving the sent message.
|
||||
* @return function
|
||||
*/
|
||||
public function newThread( $to, $subject, $message ) {
|
||||
if ( !self::$user->usernameExists( $to ) ) {
|
||||
Debug::info( 'Message->sendMessage: User not found.' );
|
||||
return false;
|
||||
}
|
||||
$fields = [
|
||||
'userTo' => self::$user->getID( $to ),
|
||||
'userFrom' => App::$activeUser->ID,
|
||||
'parent' => 0,
|
||||
'sent' => time(),
|
||||
'lastReply' => time(),
|
||||
'senderDeleted' => 0,
|
||||
'recieverDeleted' => 0,
|
||||
'isRead' => 0,
|
||||
'subject' => $subject,
|
||||
'message' => $message,
|
||||
];
|
||||
if ( !self::$db->insert( $this->tableName, $fields ) ) {
|
||||
new CustomException( 'messageSend' );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getUnreadCount( $userId ) {
|
||||
$result = self::$db->get(
|
||||
$this->tableName,
|
||||
[
|
||||
'userTo', '=', $userId,
|
||||
'AND',
|
||||
'isRead', '=', 0,
|
||||
'AND',
|
||||
'parent', '=', 0,
|
||||
'AND',
|
||||
'recieverDeleted', '=', 0,
|
||||
]
|
||||
);
|
||||
return $result->count();
|
||||
}
|
||||
|
||||
public function unreadCount() {
|
||||
if ( empty( App::$activeUser->ID ) ) {
|
||||
return 0;
|
||||
}
|
||||
return $this->getUnreadCount( App::$activeUser->ID );
|
||||
}
|
||||
|
||||
public function hasPermission( $id ) {
|
||||
if ( !Check::id( $id ) ) {
|
||||
Debug::info( 'Invalid ID' );
|
||||
return false;
|
||||
}
|
||||
$messageData = self::$db->get( 'messages', [ 'ID', '=', $id ] );
|
||||
if ( $messageData->count() == 0 ) {
|
||||
Debug::info( 'Message not found.' );
|
||||
return false;
|
||||
}
|
||||
$message = $messageData->first();
|
||||
if ( $message->userTo != App::$activeUser->ID && $message->userFrom != App::$activeUser->ID ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks a message as read. This is setup to only work
|
||||
* if the message was sent to the active user.
|
||||
*
|
||||
* @param int - The message ID you are marking as read.
|
||||
* @return bool
|
||||
*/
|
||||
public function markRead( $id ) {
|
||||
if ( !Check::id( $id ) ) {
|
||||
Debug::info( 'Invalid ID' );
|
||||
return false;
|
||||
}
|
||||
$result = self::$db->get( $this->tableName, [ 'ID', '=', $id, 'AND', 'userTo', '=', App::$activeUser->ID, 'AND', 'isRead', '=', '0' ] );
|
||||
if ( $result->count() == 0 ) {
|
||||
Debug::info( 'Failed to mark message as read.' );
|
||||
return false;
|
||||
}
|
||||
if ( !self::$db->update( $this->tableName, $id, [ 'isRead' => 1 ] ) ) {
|
||||
Debug::error( 'Failed to mark message as read.' );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function newMessageReply( $id, $message ) {
|
||||
if ( !$this->hasPermission( $id ) ) {
|
||||
Debug::info( 'Permission Denied.' );
|
||||
return false;
|
||||
}
|
||||
$messageData = self::$db->get( $this->tableName, [ 'ID', '=', $id ] )->first();
|
||||
if ( $messageData->userTo == App::$activeUser->ID ) {
|
||||
$recipient = $messageData->userFrom;
|
||||
} else {
|
||||
$recipient = $messageData->userTo;
|
||||
}
|
||||
if ( $recipient === App::$activeUser->ID ) {
|
||||
Debug::info( 'Cannot send messages to yourself' );
|
||||
return false;
|
||||
}
|
||||
if ( !self::$db->update( $this->tableName, $messageData->ID, [ 'lastReply' => time() ] ) ) {
|
||||
new CustomException( 'messagesReplyUpdate' );
|
||||
return false;
|
||||
}
|
||||
$fields = [
|
||||
'senderDeleted' => 0,
|
||||
'recieverDeleted' => 0,
|
||||
'isRead' => 0,
|
||||
'userTo' => $recipient,
|
||||
'userFrom' => App::$activeUser->ID,
|
||||
'message' => $message,
|
||||
'subject' => 're: ' . $messageData->subject,
|
||||
'sent' => time(),
|
||||
'parent' => $messageData->ID,
|
||||
'lastReply' => time(),
|
||||
];
|
||||
if ( !self::$db->insert( $this->tableName, $fields ) ) {
|
||||
new CustomException( 'messagesReplySend' );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function messageTitle( $id ) {
|
||||
if ( !$this->hasPermission( $id ) ) {
|
||||
Debug::info( 'Permission Denied.' );
|
||||
return false;
|
||||
}
|
||||
$message = self::$db->get( $this->tableName, [ 'ID', '=', $id ] )->first();
|
||||
return $message->subject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to delete messages from the DB.
|
||||
*
|
||||
* @param int $data - The ID of the message you are trying to delete.
|
||||
* @todo - done at 5 am after no sleep. This can be simplified a lot, i just wanted a working solution ASAP
|
||||
* @return bool
|
||||
*/
|
||||
public function delete( $data ) {
|
||||
if ( !is_array( $data ) ) {
|
||||
$data = [ $data ];
|
||||
}
|
||||
foreach ( $data as $instance ) {
|
||||
if ( !Check::id( $instance ) ) {
|
||||
$error = true;
|
||||
}
|
||||
if ( !$this->hasPermission( $instance ) ) {
|
||||
Debug::info( 'Permission Denied.' );
|
||||
return false;
|
||||
}
|
||||
$message = self::$db->get( $this->tableName, [ 'ID', '=', $instance ] )->first();
|
||||
if ( $message->userTo == App::$activeUser->ID ) {
|
||||
$fields = [ 'recieverDeleted' => '1' ];
|
||||
} else {
|
||||
$fields = [ 'senderDeleted' => '1' ];
|
||||
}
|
||||
if ( !self::$db->update( $this->tableName, $instance, $fields ) ) {
|
||||
$error = true;
|
||||
}
|
||||
Debug::info( "message Deleted: $instance" );
|
||||
if ( !empty( $end ) ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( !empty( $error ) ) {
|
||||
Debug::info( 'There was an error deleting one or more messages.' );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/messages/plugin.php
|
||||
*
|
||||
* This houses all of the main plugin info and functionality.
|
||||
*
|
||||
* @package TP Messages
|
||||
* @version 3.0
|
||||
* @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\Message;
|
||||
use TheTempusProject\Houdini\Classes\Components;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
|
||||
class Messages extends Plugin {
|
||||
public $pluginName = 'TP Messages';
|
||||
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 messaging system.';
|
||||
public $permissionMatrix = [
|
||||
'sendMessages' => [
|
||||
'pretty' => 'Can send Messages',
|
||||
'default' => false,
|
||||
],
|
||||
];
|
||||
private static $loaded = false;
|
||||
|
||||
public function __construct() {
|
||||
if ( ! self::$loaded ) {
|
||||
$messages = new Message;
|
||||
Components::set( 'MESSAGE_COUNT', $messages->unreadCount() );
|
||||
if ( $messages->unreadCount() > 0 ) {
|
||||
$messageBadge = Views::simpleView( 'messages.badge' );
|
||||
} else {
|
||||
$messageBadge = '';
|
||||
}
|
||||
Components::set( 'MBADGE', $messageBadge );
|
||||
if ( App::$isLoggedIn ) {
|
||||
Components::set( 'RECENT_MESSAGES', Views::simpleView( 'messages.nav.recentMessagesDropdown', $messages->getInbox( 5 ) ) );
|
||||
} else {
|
||||
Components::set( 'RECENT_MESSAGES', '' );
|
||||
}
|
||||
App::$topNavRight .= '{RECENT_MESSAGES}';
|
||||
App::$topNavRightDropdown .= '<li><a href="{ROOT_URL}messages" class="dropdown-item"><i class="fa fa-fw fa-envelope"></i> Inbox {MBADGE}</a></li>';
|
||||
self::$loaded = true;
|
||||
}
|
||||
parent::__construct();
|
||||
}
|
||||
}
|
@ -1 +0,0 @@
|
||||
<span class="badge bg-danger rounded-pill">{MESSAGE_COUNT}</span>
|
@ -1,57 +0,0 @@
|
||||
<div class="container py-4">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-4">
|
||||
<form action="" method="post" class="needs-validation">
|
||||
<legend class="mb-4">New Message</legend>
|
||||
<fieldset>
|
||||
<!-- To User Field -->
|
||||
<div class="mb-3 row">
|
||||
<label for="toUser" class="col-sm-6 col-form-label">To:</label>
|
||||
<div class="col-sm-6">
|
||||
<input
|
||||
type="text"
|
||||
class="form-control"
|
||||
name="toUser"
|
||||
id="toUser"
|
||||
value="{prepopuser}"
|
||||
required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Subject Field -->
|
||||
<div class="mb-3 row">
|
||||
<label for="subject" class="col-sm-6 col-form-label">Subject:</label>
|
||||
<div class="col-sm-6">
|
||||
<input
|
||||
type="text"
|
||||
class="form-control"
|
||||
name="subject"
|
||||
id="subject"
|
||||
required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Message Field -->
|
||||
<div class="mb-3">
|
||||
<label for="message" class="form-label">Message:</label>
|
||||
<textarea
|
||||
class="form-control"
|
||||
name="message"
|
||||
id="message"
|
||||
rows="6"
|
||||
maxlength="2000"
|
||||
required></textarea>
|
||||
</div>
|
||||
</fieldset>
|
||||
<input type="hidden" name="token" value="{TOKEN}">
|
||||
<button
|
||||
type="submit"
|
||||
name="submit"
|
||||
value="submit"
|
||||
class="btn btn-primary btn-lg">
|
||||
Send
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -1,39 +0,0 @@
|
||||
<h2>Inbox</h2>
|
||||
<form action="{ROOT_URL}messages/delete" method="post">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 20%">From</th>
|
||||
<th style="width: 25%">Subject</th>
|
||||
<th style="width: 15%">Last Reply</th>
|
||||
<th style="width: 20%"></th>
|
||||
<th style="width: 10%"></th>
|
||||
<th style="width: 10%">
|
||||
<INPUT type="checkbox" onchange="checkAll(this)" name="check.t" value="T_[]"/>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{LOOP}
|
||||
<tr {unreadBadge}>
|
||||
<td><a href="{ROOT_URL}home/profile/{userFrom}">{userFrom}</a></td>
|
||||
<td><a href="{ROOT_URL}messages/view/{ID}">{subject}</a></td>
|
||||
<td>{DTC}{lastReply}{/DTC}</td>
|
||||
<td><a href="{ROOT_URL}messages/read/{ID}">Mark as read</a></td>
|
||||
<td><a href="{ROOT_URL}messages/delete/{ID}">Delete</a></td>
|
||||
<td>
|
||||
<input type="checkbox" value="{ID}" name="T_[]">
|
||||
</td>
|
||||
</tr>
|
||||
{/LOOP}
|
||||
{ALT}
|
||||
<tr>
|
||||
<td align="center" colspan="6">
|
||||
No Messages.
|
||||
</td>
|
||||
</tr>
|
||||
{/ALT}
|
||||
</tbody>
|
||||
</table>
|
||||
<button name="submit" value="submit" type="submit" class="btn btn-sm btn-danger">Delete</button> <a href="{ROOT_URL}messages/create" class="btn btn-sm btn-primary">New message</a>
|
||||
</form>
|
@ -1,8 +0,0 @@
|
||||
<div class="context-main context-main-bg col-10 offset-1 my-3 p-3">
|
||||
<div class="my-3 p-3">
|
||||
{message_inbox}
|
||||
</div>
|
||||
<div class="my-3 p-3">
|
||||
{message_outbox}
|
||||
</div>
|
||||
</div>
|
@ -1,43 +0,0 @@
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-6 col-lg-6 col-sm-offset-0 col-md-offset-3 col-lg-offset-3 top-pad" >
|
||||
<div class="card panel-primary">
|
||||
{LOOP}
|
||||
{SINGLE}
|
||||
<div class="card-header">
|
||||
<h3 class="card-title">{subject}</h3>
|
||||
</div>
|
||||
{/SINGLE}
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-md-3 col-lg-3 " align="center">
|
||||
<a href="{ROOT_URL}home/profile/{userFrom}">{userFrom}</a><br>
|
||||
<img alt="User Pic" src="{ROOT_URL}{fromAvatar}" class="img-circle img-responsive">
|
||||
</div>
|
||||
<div class=" col-md-9 col-lg-9 ">
|
||||
<table class="table table-user-information">
|
||||
<tbody>
|
||||
<td>{message}</td>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
{ADMIN}
|
||||
{ID}
|
||||
<span class="float-right">
|
||||
{DTC}{sent}{/DTC}
|
||||
</span>
|
||||
{/ADMIN}
|
||||
</div>
|
||||
{/LOOP}
|
||||
</div>
|
||||
<form action="{ROOT_URL}messages/reply" method="post">
|
||||
<input type="hidden" name="token" value="{TOKEN}">
|
||||
<input type="hidden" name="messageID" value="{PID}">
|
||||
<button name="submit" value="reply" type="submit" class="btn btn-sm btn-primary">Reply</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -1,37 +0,0 @@
|
||||
<div class="context-main context-main-bg col-8 offset-2 my-3 p-3">
|
||||
<div class="col-sm-12 col-md-6 col-lg-6 col-sm-offset-0 col-md-offset-3 col-lg-offset-3 top-pad" >
|
||||
<div class="card panel-primary">
|
||||
{LOOP}
|
||||
{SINGLE}
|
||||
<div class="card-header context-main-bg">
|
||||
<h5 class="card-title context-main">{subject}</h5>
|
||||
</div>
|
||||
{/SINGLE}
|
||||
<div class="card-body context-second-bg">
|
||||
<div class="row">
|
||||
<div class="col-md-3 col-lg-3 text-center">
|
||||
<a href="{ROOT_URL}home/profile/{userFrom}">{userFrom}</a><br>
|
||||
<img alt="User Pic" src="{ROOT_URL}{fromAvatar}" class="img-circle img-fluid">
|
||||
</div>
|
||||
<div class=" col-md-9 col-lg-9 context-main">
|
||||
{message}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer context-main-bg">
|
||||
{ADMIN}
|
||||
{ID}
|
||||
<span class="float-right">
|
||||
{DTC}{sent}{/DTC}
|
||||
</span>
|
||||
{/ADMIN}
|
||||
</div>
|
||||
{/LOOP}
|
||||
</div>
|
||||
<form action="{ROOT_URL}messages/reply" method="post">
|
||||
<input type="hidden" name="token" value="{TOKEN}">
|
||||
<input type="hidden" name="messageID" value="{PID}">
|
||||
<button name="submit" value="reply" type="submit" class="btn btn-md btn-primary my-4">Reply</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
@ -1,46 +0,0 @@
|
||||
<div class="dropdown nav-item mx-2">
|
||||
<a
|
||||
href="#"
|
||||
class="d-flex align-items-center text-white text-decoration-none dropdown-toggle"
|
||||
id="messagesDropdown"
|
||||
data-bs-toggle="dropdown"
|
||||
aria-haspopup="true"
|
||||
aria-expanded="false">
|
||||
<i class="fa fa-fw fa-envelope"></i><span class="">{MBADGE}</span>
|
||||
</a>
|
||||
<ul class="dropdown-menu dropdown-menu-dark dropdown-menu-end text-small shadow" aria-labelledby="messagesDropdown">
|
||||
{LOOP}
|
||||
<!-- Message Item -->
|
||||
<li>
|
||||
<a href="{ROOT_URL}messages/view/{ID}" class="dropdown-item">
|
||||
<div class="d-flex">
|
||||
<h5 class="media-heading text-start">
|
||||
<img class="" style="width: 40px;" src="{ROOT_URL}{fromAvatar}" alt="">
|
||||
<strong>{userFrom}</strong>
|
||||
</h5>
|
||||
<div class="text-end">
|
||||
<div class="media-body">
|
||||
<p class="small text-muted mb-1"><i class="fa fa-clock-o me-1"></i> {DTC}{lastReply}{/DTC}</p>
|
||||
<span>{summary}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
{/LOOP}
|
||||
{ALT}
|
||||
<li class="px-3 text-center">
|
||||
<strong>No Messages</strong>
|
||||
</li>
|
||||
{/ALT}
|
||||
<!-- Footer -->
|
||||
<li>
|
||||
<hr class="dropdown-divider">
|
||||
</li>
|
||||
<li>
|
||||
<a href="/messages" class="dropdown-item text-center">
|
||||
Read All New Messages
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
@ -1,37 +0,0 @@
|
||||
<h2>Outbox</h2>
|
||||
<form action="{ROOT_URL}messages/delete" method="post">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 20%">To</th>
|
||||
<th style="width: 40%">Subject</th>
|
||||
<th style="width: 20%">Sent</th>
|
||||
<th style="width: 10%"></th>
|
||||
<th style="width: 10%">
|
||||
<INPUT type="checkbox" onchange="checkAll(this)" name="check.e" value="F_[]"/>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{LOOP}
|
||||
<tr>
|
||||
<td><a href="{ROOT_URL}home/profile/{userTo}">{userTo}</a></td>
|
||||
<td><a href="{ROOT_URL}messages/view/{ID}">{subject}</a></td>
|
||||
<td>{DTC date}{sent}{/DTC}</td>
|
||||
<td><a href="{ROOT_URL}messages/delete/{ID}">Delete</a></td>
|
||||
<td>
|
||||
<input type="checkbox" value="{ID}" name="F_[]">
|
||||
</td>
|
||||
</tr>
|
||||
{/LOOP}
|
||||
{ALT}
|
||||
<tr>
|
||||
<td align="center" colspan="6">
|
||||
No Messages
|
||||
</td>
|
||||
</tr>
|
||||
{/ALT}
|
||||
</tbody>
|
||||
</table>
|
||||
<button name="submit" value="submit" type="submit" class="btn btn-sm btn-danger">Delete</button>
|
||||
</form>
|
@ -1,18 +0,0 @@
|
||||
<div class="context-main context-main-bg col-8 offset-2 my-3 p-3">
|
||||
<form action="" method="post" class="form-horizontal">
|
||||
<legend class="text-center">Reply</legend>
|
||||
<fieldset>
|
||||
<div class="form-group">
|
||||
<div class="col-6 offset-3">
|
||||
<label for="message" class="control-label">Message:</label>
|
||||
<textarea class="form-control" name="message" maxlength="2000" rows="10" cols="50" id="message"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<input type="hidden" name="messageID" value="{messageID}">
|
||||
<input type="hidden" name="token" value="{TOKEN}">
|
||||
<div class="text-center">
|
||||
<button name="submit" value="submit" type="submit" class="btn btn-lg btn-primary center-block my-3">Send</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
@ -1 +0,0 @@
|
||||
class="bg-info"
|
@ -1,85 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/notifications/controllers/admin/notifications.php
|
||||
*
|
||||
* This is the notifications admin controller.
|
||||
*
|
||||
* @package TP Notifications
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Controllers\Admin;
|
||||
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\Houdini\Classes\Issues;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Houdini\Classes\Navigation;
|
||||
use TheTempusProject\Houdini\Classes\Components;
|
||||
use TheTempusProject\Classes\AdminController;
|
||||
use TheTempusProject\Models\Notification as NotificationsModel;
|
||||
use TheTempusProject\Models\Group;
|
||||
use TheTempusProject\Models\User;
|
||||
use TheTempusProject\Houdini\Classes\Forms;
|
||||
use TheTempusProject\Classes\Forms as FormChecker;
|
||||
|
||||
class Notifications extends AdminController {
|
||||
protected static $notifications;
|
||||
public static $user;
|
||||
public static $group;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$title = 'Admin - Notifications';
|
||||
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 ) {
|
||||
// this is just a simple form to allow admins to send notifications
|
||||
return $this->create();
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$select = Forms::getSelectHtml(
|
||||
'groupSelect',
|
||||
self::$group->listGroupsSimple( true )
|
||||
);
|
||||
Components::set( 'groupSelect', $select );
|
||||
if ( ! Input::exists( 'submit' ) ) {
|
||||
return Views::view( 'notifications.admin.send' );
|
||||
}
|
||||
if ( ! FormChecker::check( 'createNotification' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your request.' => Check::userErrors() ] );
|
||||
return Views::view( 'notifications.admin.send' );
|
||||
}
|
||||
if ( Input::exists( 'expires' ) ) {
|
||||
$expiresAt = time() + intval( Input::post( 'expires' ) );
|
||||
} else {
|
||||
$expiresAt = 0;
|
||||
}
|
||||
|
||||
if ( Input::exists( 'groupSelect' ) && Input::post( 'groupSelect' ) != 0 && Input::post( 'groupSelect' ) != 'all' ) {
|
||||
$list = self::$group->listMembers( Input::post( 'groupSelect' ) );
|
||||
} else {
|
||||
$list = self::$user->userList();
|
||||
}
|
||||
|
||||
$results = [];
|
||||
foreach ( $list as $recipient ) {
|
||||
$results[] = self::$notifications->create( Input::post( 'notification' ), 'Admin Issued', $recipient->ID, $expiresAt );
|
||||
}
|
||||
|
||||
// $result = self::$notifications->create( Input::post( 'notification' ), 'Admin Issued', XXXXXXX_user_idsXXXXXX, $expiresAt );
|
||||
if ( ! empty( $results ) ) {
|
||||
Issues::add( 'success', 'Your notification has been sent.' );
|
||||
} else {
|
||||
Issues::add( 'error', [ 'There was an unknown error submitting your data.' => Check::userErrors() ] );
|
||||
}
|
||||
Views::view( 'notifications.admin.send' );
|
||||
}
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/notifications/controllers/notifications.php
|
||||
*
|
||||
* This is the home controller for the notifications plugin.
|
||||
*
|
||||
* @package TP Notifications
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Controllers;
|
||||
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Houdini\Classes\Issues;
|
||||
use TheTempusProject\Classes\Controller;
|
||||
use TheTempusProject\Models\Notification as NotificationsModel;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
use TheTempusProject\Hermes\Functions\Redirect;
|
||||
use TheTempusProject\Bedrock\Functions\Session;
|
||||
|
||||
class Notifications extends Controller {
|
||||
protected static $notifications;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$notifications = new NotificationsModel;
|
||||
self::$title = 'Notifications - {SITENAME}';
|
||||
self::$pageDescription = 'Your recent notifications';
|
||||
if ( ! App::$isLoggedIn ) {
|
||||
Session::flash( 'error', 'You do not have permission to access this page.' );
|
||||
return Redirect::home();
|
||||
}
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$notifications = self::$notifications->getByUser( 10 );
|
||||
Views::view( 'notifications.list', $notifications );
|
||||
}
|
||||
|
||||
public function markRead( $id = null ) {
|
||||
$notification = self::$notifications->findById( $id );
|
||||
if ( $notification == false ) {
|
||||
Issues::add( 'error', 'Notification not found.' );
|
||||
return $this->index();
|
||||
}
|
||||
if ( $notification->userID != App::$activeUser->ID ) {
|
||||
Issues::add( 'error', 'You do not have permission to modify this notification.' );
|
||||
return $this->index();
|
||||
}
|
||||
$result = self::$notifications->markSeen( $id );
|
||||
if ( $result == true ) {
|
||||
Issues::add( 'success', 'Notification marked as read.' );
|
||||
} else {
|
||||
Issues::add( 'notice', 'There was an problem updating your notification.' );
|
||||
}
|
||||
return $this->index();
|
||||
}
|
||||
|
||||
public function delete( $id = null ) {
|
||||
$notification = self::$notifications->findById( $id );
|
||||
if ( $notification == false ) {
|
||||
Issues::add( 'error', 'Notification not found.' );
|
||||
return $this->index();
|
||||
}
|
||||
if ( $notification->userID != App::$activeUser->ID ) {
|
||||
Issues::add( 'error', 'You do not have permission to modify this notification.' );
|
||||
return $this->index();
|
||||
}
|
||||
$result = self::$notifications->delete( $id );
|
||||
if ( $result == true ) {
|
||||
Issues::add( 'success', 'Notification deleted.' );
|
||||
} else {
|
||||
Issues::add( 'notice', 'There was an problem deleting your notification.' );
|
||||
}
|
||||
return $this->index();
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/notifications/forms.php
|
||||
*
|
||||
* This houses all of the form checking functions for this plugin.
|
||||
*
|
||||
* @package TP Notifications
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Plugins\Notifications;
|
||||
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\Bedrock\Functions\Check;
|
||||
use TheTempusProject\Classes\Forms;
|
||||
|
||||
class NotificationForms extends Forms {
|
||||
/**
|
||||
* Adds these functions to the form list.
|
||||
*/
|
||||
public function __construct() {
|
||||
self::addHandler( 'createNotification', __CLASS__, 'createNotification' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the createNotification form.
|
||||
*
|
||||
* @return {bool}
|
||||
*/
|
||||
public static function createNotification() {
|
||||
if ( ! Input::exists( 'notification' ) ) {
|
||||
Check::addUserError( 'You must provide a notification.' );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
new NotificationForms;
|
@ -1,146 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/notifications/models/notification.php
|
||||
*
|
||||
* This class is used for the manipulation of the notifications database table.
|
||||
*
|
||||
* @package TP Notifications
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Models;
|
||||
|
||||
use TheTempusProject\Bedrock\Functions\Check;
|
||||
use TheTempusProject\Canary\Bin\Canary as Debug;
|
||||
use TheTempusProject\Classes\DatabaseModel;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Canary\Classes\CustomException;
|
||||
|
||||
class Notification extends DatabaseModel {
|
||||
public $tableName = 'notifications';
|
||||
public $databaseMatrix = [
|
||||
[ 'notification', 'text', '' ],
|
||||
[ 'origin', 'varchar', '128' ],
|
||||
[ 'userID', 'int', '11' ],
|
||||
[ 'createdAt', 'int', '11' ],
|
||||
[ 'expiresAt', 'int', '11' ],
|
||||
[ 'deletedAt', 'int', '11' ],
|
||||
[ 'seenAt', 'int', '11' ],
|
||||
];
|
||||
|
||||
public function getUnreadCount( $userID ) {
|
||||
$result = self::$db->get(
|
||||
$this->tableName,
|
||||
[
|
||||
'userID', '=', $userID,
|
||||
'AND',
|
||||
'deletedAt', '=', '0',
|
||||
'AND',
|
||||
'seenAt', '=', '0',
|
||||
'AND',
|
||||
'expiresAt', '<', time(),
|
||||
]
|
||||
);
|
||||
return $result->count();
|
||||
}
|
||||
|
||||
public function create( $notification, $origin, $userID, $expiresAt = '0', $deletedAt = '0', $seenAt = '0' ) {
|
||||
$fields = [
|
||||
'notification' => $notification,
|
||||
'origin' => $origin,
|
||||
'userID' => $userID,
|
||||
'createdAt' => time(),
|
||||
'expiresAt' => $expiresAt,
|
||||
'deletedAt' => $deletedAt,
|
||||
'seenAt' => $seenAt,
|
||||
];
|
||||
if ( !self::$db->insert( $this->tableName, $fields ) ) {
|
||||
Debug::info( 'Events::create - failed to insert to db' );
|
||||
return false;
|
||||
}
|
||||
return self::$db->lastId();
|
||||
}
|
||||
|
||||
public function getByUser( $limit = 0 ) {
|
||||
$whereClause = [
|
||||
'userID', '=', App::$activeUser->ID,
|
||||
'AND',
|
||||
'deletedAt', '=', '0',
|
||||
'AND',
|
||||
'expiresAt', '<', time(),
|
||||
];
|
||||
if ( empty( $limit ) ) {
|
||||
$notifications = self::$db->get( $this->tableName, $whereClause );
|
||||
} else {
|
||||
$notifications = self::$db->get( $this->tableName, $whereClause, 'ID', 'DESC', [0, $limit] );
|
||||
}
|
||||
if ( !$notifications->count() ) {
|
||||
Debug::info( 'Notification:getByUser No Notifications found' );
|
||||
return false;
|
||||
}
|
||||
return $this->filter( $notifications->results() );
|
||||
}
|
||||
|
||||
public function markSeen( $id ) {
|
||||
if ( !Check::id( $id ) ) {
|
||||
Debug::info( 'Notifications: illegal ID.' );
|
||||
return false;
|
||||
}
|
||||
$fields = [
|
||||
'seenAt' => time(),
|
||||
];
|
||||
$notification = self::findById( $id );
|
||||
if ( ! $notification ) {
|
||||
Debug::error( "Notifications: $id not updated" );
|
||||
return false;
|
||||
}
|
||||
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
|
||||
new CustomException( 'notificationUpdate' );
|
||||
Debug::error( "Notifications: $id not updated" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function delete( $id ) {
|
||||
if ( !Check::id( $id ) ) {
|
||||
Debug::info( 'Notifications: illegal ID.' );
|
||||
return false;
|
||||
}
|
||||
$fields = [
|
||||
'deletedAt' => time(),
|
||||
];
|
||||
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
|
||||
new CustomException( 'notificationDelete' );
|
||||
Debug::error( "Notifications: $id not updated" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function filter( $messageArray, $filters = [] ) {
|
||||
$out = [];
|
||||
foreach ( $messageArray as $message ) {
|
||||
if ( !is_object( $message ) ) {
|
||||
$message = $messageArray;
|
||||
$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>';
|
||||
} else {
|
||||
$message->unseenBadge = '';
|
||||
$message->markReadLink = '';
|
||||
}
|
||||
$out[] = (object) $message;
|
||||
if ( !empty( $end ) ) {
|
||||
$out = $out[0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/notifications/plugin.php
|
||||
*
|
||||
* This houses all of the main plugin info and functionality.
|
||||
*
|
||||
* @package TP Notifications
|
||||
* @version 3.0
|
||||
* @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;
|
||||
|
||||
class Notifications extends Plugin {
|
||||
public $pluginName = 'TP Notifications';
|
||||
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 notification system.';
|
||||
public $permissionMatrix = [
|
||||
'sendNotifications' => [
|
||||
'pretty' => 'Can send notifications',
|
||||
'default' => false,
|
||||
],
|
||||
];
|
||||
public $admin_links = [
|
||||
[
|
||||
'text' => '<i class="fa fa-fw fa-bell"></i> Notify',
|
||||
'url' => '{ROOT_URL}admin/notifications',
|
||||
],
|
||||
];
|
||||
private static $loaded = false;
|
||||
public function __construct( $load = false ) {
|
||||
parent::__construct( $load );
|
||||
if ( $this->checkEnabled() && App::$isLoggedIn ) {
|
||||
$notifications = new Notification;
|
||||
Components::set( 'notificationCount', $notifications->getUnreadCount( App::$activeUser->ID ) );
|
||||
if ( $notifications->getUnreadCount( App::$activeUser->ID ) > 0 ) {
|
||||
$messageBadge = Views::simpleView( 'notifications.badge' );
|
||||
} else {
|
||||
$messageBadge = '';
|
||||
}
|
||||
Components::set( 'NBADGE', $messageBadge );
|
||||
if ( ! self::$loaded ) {
|
||||
if ( App::$isLoggedIn ) {
|
||||
Components::set( 'recentNotifications', Views::simpleView( 'notifications.nav.recentNotificationsDropdown', $notifications->getByUser( 10 ) ) );
|
||||
} else {
|
||||
Components::set( 'recentNotifications', '' );
|
||||
}
|
||||
App::$topNavRight .= '{recentNotifications}';
|
||||
App::$topNavRightDropdown .= '<li><a href="{ROOT_URL}notifications" class="dropdown-item"><i class="fa fa-fw fa-bell"></i> Notifications {NBADGE}</a></li>';
|
||||
self::$loaded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
<div class="context-main-bg context-main p-3">
|
||||
<legend class="text-center">Send Notification</legend>
|
||||
<hr>
|
||||
{ADMIN_BREADCRUMBS}
|
||||
|
||||
<form action="" method="post" enctype="multipart/form-data">
|
||||
<fieldset>
|
||||
<!-- Group -->
|
||||
<div class="mb-3 row">
|
||||
<label for="groupSelect" class="col-lg-3 col-form-label text-end">Group:</label>
|
||||
<div class="col-lg-6">
|
||||
{groupSelect}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Recipients -->
|
||||
<div class="mb-3 row">
|
||||
<label for="expiration" class="col-lg-3 col-form-label text-end">Expiration:</label>
|
||||
<div class="col-lg-6">
|
||||
<select class="form-control" name="expiration" id="expiration">
|
||||
<option value="0">forever</option>
|
||||
<option value="1800">30 Minutes</option>
|
||||
<option value="3600">60 Minutes</option>
|
||||
<option value="14400">4 hours</option>
|
||||
<option value="28800">8 hours</option>
|
||||
<option value="43200">12 hours</option>
|
||||
<option value="86400">24 hours</option>
|
||||
<option value="172800">2 days</option>
|
||||
<option value="259200">3 days</option>
|
||||
<option value="432000">5 days</option>
|
||||
<option value="604800">7 days</option>
|
||||
<option value="1209600">2 weeks</option>
|
||||
<option value="1814400">3 weeks</option>
|
||||
<option value="2419200">4 weeks</option>
|
||||
<option value="2592000">1 month</option>
|
||||
<option value="5184000">2 months</option>
|
||||
<option value="7776000">3 months</option>
|
||||
<option value="15552000">6 months</option>
|
||||
<option value="31536000">12 months</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Notification -->
|
||||
<div class="mb-3 row">
|
||||
<label for="notification" class="col-lg-3 col-form-label text-end">Notification:</label>
|
||||
<div class="col-lg-6">
|
||||
<textarea class="form-control" name="notification" id="notification" rows="6" maxlength="2000" required></textarea>
|
||||
<small class="form-text text-muted">Max: 2000 characters</small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Hidden Token -->
|
||||
<input type="hidden" name="token" value="{TOKEN}">
|
||||
</fieldset>
|
||||
|
||||
<!-- Submit Button -->
|
||||
<div class="text-center">
|
||||
<button type="submit" name="submit" value="submit" class="btn btn-primary btn-lg center-block">Send</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
@ -1 +0,0 @@
|
||||
<span class="badge bg-danger rounded-pill">{notificationCount}</span>
|
@ -1,38 +0,0 @@
|
||||
<div class="col-8 mx-auto p-4 rounded shadow-sm context-main-bg my-4">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-8">
|
||||
<legend class="text-center">Notifications</legend>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 90%"></th>
|
||||
<th style="width: 5%"></th>
|
||||
<th style="width: 5%"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{LOOP}
|
||||
<tr {unseenBadge}>
|
||||
<td class=" context-main">{notification}</td>
|
||||
<td>
|
||||
{markReadLink}
|
||||
</td>
|
||||
<td>
|
||||
<a href="{ROOT_URL}notifications/delete/{ID}" class="btn btn-sm btn-danger">
|
||||
<i class="fa fa-fw fa-trash"></i>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
{/LOOP}
|
||||
{ALT}
|
||||
<tr>
|
||||
<td colspan="7" class=" context-main">
|
||||
No Notifications
|
||||
</td>
|
||||
</tr>
|
||||
{/ALT}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -1,41 +0,0 @@
|
||||
<!-- Notifications Dropdown -->
|
||||
<div class="dropdown nav-item mx-2">
|
||||
<a
|
||||
href="#"
|
||||
class="d-flex align-items-center text-white text-decoration-none dropdown-toggle"
|
||||
id="notificationsDropdown"
|
||||
data-bs-toggle="dropdown"
|
||||
aria-haspopup="true"
|
||||
aria-expanded="false">
|
||||
<i class="fa fa-fw fa-bell"></i><span class="">{NBADGE}</span>
|
||||
</a>
|
||||
<ul class="dropdown-menu dropdown-menu-dark dropdown-menu-end text-small shadow" aria-labelledby="notificationsDropdown">
|
||||
{LOOP}
|
||||
<!-- Notification Item -->
|
||||
<li>
|
||||
<a href="{ROOT_URL}notifications" class="dropdown-item">
|
||||
<div class="media">
|
||||
<div class="media-body">
|
||||
<p class="small text-muted mb-1"><i class="fa fa-clock-o me-1"></i> {DTC}{createdAt}{/DTC}</p>
|
||||
<span>{notification}</span>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
{/LOOP}
|
||||
{ALT}
|
||||
<li class="px-3 text-center">
|
||||
<strong>No Notifications</strong>
|
||||
</li>
|
||||
{/ALT}
|
||||
<!-- Footer -->
|
||||
<li>
|
||||
<hr class="dropdown-divider">
|
||||
</li>
|
||||
<li>
|
||||
<a href="/notifications" class="dropdown-item text-center">
|
||||
See All Notifications
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
@ -1 +0,0 @@
|
||||
class="bg-info"
|
@ -1,47 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/subscribe/plugin.php
|
||||
*
|
||||
* This houses all of the main plugin info and functionality.
|
||||
*
|
||||
* @package TP Subscribe
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Plugins;
|
||||
|
||||
use ReflectionClass;
|
||||
use TheTempusProject\Classes\Installer;
|
||||
use TheTempusProject\Houdini\Classes\Navigation;
|
||||
use TheTempusProject\Classes\Plugin;
|
||||
use TheTempusProject\Houdini\Classes\Components;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
|
||||
class Subscribe extends Plugin {
|
||||
private static $loaded = false;
|
||||
public $pluginName = 'TP Subscribe';
|
||||
public $pluginAuthor = 'JoeyK';
|
||||
public $pluginWebsite = 'https://TheTempusProject.com';
|
||||
public $modelVersion = '1.0';
|
||||
public $pluginVersion = '3.0';
|
||||
public $pluginDescription = 'A simple plugin to add a method for users to share their email.';
|
||||
public $admin_links = [
|
||||
[
|
||||
'text' => '<i class="fa fa-fw fa-address-book"></i> Subscriptions',
|
||||
'url' => '{ROOT_URL}admin/subscriptions',
|
||||
],
|
||||
];
|
||||
|
||||
public function __construct( $load = false ) {
|
||||
parent::__construct( $load );
|
||||
if ( ! self::$loaded ) {
|
||||
if ( $this->checkEnabled() ) {
|
||||
Components::append( 'FOOTER_RIGHT', Views::simpleView( 'subscribe.footer.right') );
|
||||
}
|
||||
self::$loaded = true;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
<div class="context-main-bg context-main p-3">
|
||||
<legend class="text-center">Add Subscriber</legend>
|
||||
<hr>
|
||||
{ADMIN_BREADCRUMBS}
|
||||
<form action="" method="post">
|
||||
<fieldset>
|
||||
<!-- Subject -->
|
||||
<div class="mb-3 row">
|
||||
<label for="email" class="col-lg-5 col-form-label text-end">Email:</label>
|
||||
<div class="col-lg-3">
|
||||
<input type="email" class="form-control" name="email" id="email" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Hidden Token -->
|
||||
<input type="hidden" name="token" value="{TOKEN}">
|
||||
</fieldset>
|
||||
|
||||
<!-- Submit Button -->
|
||||
<div class="text-center">
|
||||
<button type="submit" name="submit" value="submit" class="btn btn-primary btn-lg center-block">Submit</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
@ -1,40 +0,0 @@
|
||||
<div class="context-main-bg context-main p-3">
|
||||
<legend class="text-center">Subscribers</legend>
|
||||
<hr>
|
||||
{ADMIN_BREADCRUMBS}
|
||||
<form action="{ROOT_URL}admin/subscriptions/delete" method="post">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 5%">ID</th>
|
||||
<th style="width: 85%">email</th>
|
||||
<th style="width: 5%"></th>
|
||||
<th style="width: 5%">
|
||||
<input type="checkbox" onchange="checkAll(this)" name="check.s" value="S_[]">
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{LOOP}
|
||||
<tr>
|
||||
<td align="center">{ID}</td>
|
||||
<td>{EMAIL}</td>
|
||||
<td><a href="{ROOT_URL}admin/subscriptions/delete/{ID}" class="btn btn-sm btn-danger"><i class="fa fa-fw fa-trash"></i></a></td>
|
||||
<td>
|
||||
<input type="checkbox" value="{ID}" name="S_[]">
|
||||
</td>
|
||||
</tr>
|
||||
{/LOOP}
|
||||
{ALT}
|
||||
<tr>
|
||||
<td align="center" colspan="6">
|
||||
No results to show.
|
||||
</td>
|
||||
</tr>
|
||||
{/ALT}
|
||||
</tbody>
|
||||
</table>
|
||||
<a href="{ROOT_URL}admin/subscriptions/add" class="btn btn-sm btn-primary">Add</a>
|
||||
<button name="submit" value="submit" type="submit" class="btn btn-sm btn-danger"><i class="fa fa-fw fa-trash"></i></button>
|
||||
</form>
|
||||
</div>
|
@ -1,11 +0,0 @@
|
||||
<div class="col-md-5 offset-md-1 mb-3 text-center">
|
||||
<h5 class="">Subscribe</h5>
|
||||
<div class="d-flex flex-column flex-sm-row gap-2 justify-content-center mx-auto">
|
||||
<form action="{ROOT_URL}subscribe/home" method="post" class="form-horizontal">
|
||||
<label for="email" class="visually-hidden">Email address</label>
|
||||
<input name="email" id="email" type="email" class="form-control my-2" placeholder="Email address" autocomplete="email">
|
||||
<input type="hidden" name="token" value="{TOKEN}">
|
||||
<button class="btn btn-primary my-2 w-100" name="submit" value="submit" type="submit">Subscribe</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
Reference in New Issue
Block a user