Initial commit
This commit is contained in:
58
app/plugins/feedback/controllers/admin/feedback.php
Normal file
58
app/plugins/feedback/controllers/admin/feedback.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/feedback/controllers/admin/feedback.php
|
||||
*
|
||||
* This is the feedback admin controller.
|
||||
*
|
||||
* @package TP Feedback
|
||||
* @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\Feedback as FeedbackModel;
|
||||
|
||||
class Feedback extends AdminController {
|
||||
protected static $feedback;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$title = 'Admin - Feedback';
|
||||
self::$feedback = new FeedbackModel;
|
||||
$view = Navigation::activePageSelect( 'nav.admin', '/admin/feedback' );
|
||||
Components::set( 'ADMINNAV', $view );
|
||||
}
|
||||
|
||||
public function view( $id = null ) {
|
||||
Views::view( 'feedback.admin.view', self::$feedback->findById( $id ) );
|
||||
}
|
||||
|
||||
public function delete( $data = null ) {
|
||||
if ( Input::exists( 'submit' ) ) {
|
||||
$data = Input::post( 'F_' );
|
||||
}
|
||||
if ( self::$feedback->delete( (array) $data ) ) {
|
||||
Issues::add( 'success', 'feedback deleted' );
|
||||
} else {
|
||||
Issues::add( 'error', 'There was an error with your request.' );
|
||||
}
|
||||
$this->index();
|
||||
}
|
||||
|
||||
public function clear( $data = null ) {
|
||||
self::$feedback->clear();
|
||||
$this->index();
|
||||
}
|
||||
|
||||
public function index( $data = null ) {
|
||||
Views::view( 'feedback.admin.list', self::$feedback->list() );
|
||||
}
|
||||
}
|
47
app/plugins/feedback/controllers/feedback.php
Normal file
47
app/plugins/feedback/controllers/feedback.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/feedback/controllers/feedback.php
|
||||
*
|
||||
* This is the home controller for the feedback plugin.
|
||||
*
|
||||
* @package TP Feedback
|
||||
* @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\Classes\Forms;
|
||||
use TheTempusProject\Bedrock\Functions\Check;
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\Bedrock\Functions\Session;
|
||||
use TheTempusProject\Hermes\Functions\Redirect;
|
||||
use TheTempusProject\Models\Feedback as FeedbackModel;
|
||||
|
||||
class Feedback extends Controller {
|
||||
protected static $feedback;
|
||||
|
||||
public function index() {
|
||||
self::$feedback = new FeedbackModel;
|
||||
self::$title = 'Feedback - {SITENAME}';
|
||||
self::$pageDescription = 'At {SITENAME}, we value our users\' input. You can provide any feedback or suggestions using this form.';
|
||||
if ( !Input::exists() ) {
|
||||
return Views::view( 'feedback.feedback' );
|
||||
}
|
||||
if ( !Forms::check( 'feedback' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your form, please check your submission and try again.' => Check::userErrors() ] );
|
||||
return Views::view( 'feedback.feedback' );
|
||||
}
|
||||
$result = self::$feedback->create( Input::post( 'name' ), Input::post( 'feedbackEmail' ), Input::post( 'entry' ) );
|
||||
if ( $result ) {
|
||||
Session::flash( 'success', 'Thank you! Your feedback has been received.' );
|
||||
Redirect::to( 'home/index' );
|
||||
} else {
|
||||
Issues::add( 'error', [ 'There was an error with your form, please check your submission and try again.' => Check::userErrors() ] );
|
||||
}
|
||||
}
|
||||
}
|
56
app/plugins/feedback/forms.php
Normal file
56
app/plugins/feedback/forms.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/feedback/forms.php
|
||||
*
|
||||
* This houses all of the form checking functions for this plugin.
|
||||
*
|
||||
* @package TP Feedback
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Plugins\Feedback;
|
||||
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\Bedrock\Functions\Check;
|
||||
use TheTempusProject\Classes\Forms;
|
||||
|
||||
class FeedbackForms extends Forms {
|
||||
/**
|
||||
* Adds these functions to the form list.
|
||||
*/
|
||||
public function __construct() {
|
||||
self::addHandler( 'feedback', __CLASS__, 'feedback' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the feedback form.
|
||||
*
|
||||
* @return {bool}
|
||||
*/
|
||||
public static function feedback() {
|
||||
if ( !Input::exists( 'name' ) ) {
|
||||
Check::addUserError( 'You must provide a name.' );
|
||||
return false;
|
||||
}
|
||||
if ( !Check::name( Input::post( 'name' ) ) ) {
|
||||
Check::addUserError( 'Invalid name.' );
|
||||
return false;
|
||||
}
|
||||
if ( !empty( Input::post( 'feedbackEmail' ) ) && !Check::email( Input::post( 'feedbackEmail' ) ) ) {
|
||||
Check::addUserError( 'Invalid Email.' );
|
||||
return false;
|
||||
}
|
||||
if ( Input::post( 'entry' ) == '' ) {
|
||||
Check::addUserError( 'Feedback cannot be empty.' );
|
||||
return false;
|
||||
}
|
||||
if ( !Check::token() ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
new FeedbackForms;
|
84
app/plugins/feedback/models/feedback.php
Normal file
84
app/plugins/feedback/models/feedback.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/feedback/models/feedback.php
|
||||
*
|
||||
* This class is used for the manipulation of the feedback database table.
|
||||
*
|
||||
* @todo make this send a confirmation email
|
||||
*
|
||||
* @package TP Feedback
|
||||
* @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\Classes\Config;
|
||||
use TheTempusProject\Bedrock\Functions\Check;
|
||||
use TheTempusProject\Canary\Canary as Debug;
|
||||
use TheTempusProject\Classes\DatabaseModel;
|
||||
use TheTempusProject\Plugins\Feedback as Plugin;
|
||||
|
||||
class Feedback extends DatabaseModel {
|
||||
public $tableName = 'feedback';
|
||||
public $databaseMatrix = [
|
||||
[ 'name', 'varchar', '128' ],
|
||||
[ 'time', 'int', '10' ],
|
||||
[ 'email', 'varchar', '128' ],
|
||||
[ 'ip', 'varchar', '64' ],
|
||||
[ 'feedback', 'text', '' ],
|
||||
];
|
||||
public $plugin;
|
||||
|
||||
/**
|
||||
* The model constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->plugin = new Plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves a feedback form to the db.
|
||||
*
|
||||
* @param string $name -the name on the form
|
||||
* @param string $email -the email provided
|
||||
* @param string $feedback -contents of the feedback form.
|
||||
* @return bool
|
||||
*/
|
||||
public function create( $name, $email, $feedback ) {
|
||||
if ( !$this->plugin->checkEnabled() ) {
|
||||
Debug::info( 'Feedback is disabled in the config.' );
|
||||
return false;
|
||||
}
|
||||
$fields = [
|
||||
'name' => $name,
|
||||
'email' => $email,
|
||||
'feedback' => $feedback,
|
||||
'time' => time(),
|
||||
'ip' => $_SERVER['REMOTE_ADDR'],
|
||||
];
|
||||
if ( !self::$db->insert( $this->tableName, $fields ) ) {
|
||||
Debug::info( 'Feedback::create - failed to insert to db' );
|
||||
return false;
|
||||
}
|
||||
return self::$db->lastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to clear feedback from the DB.
|
||||
*
|
||||
* @todo is there a way i could check for success here I'm pretty sure this is just a bad idea?
|
||||
* @return bool
|
||||
*/
|
||||
public function clear() {
|
||||
if ( empty( self::$log ) ) {
|
||||
self::$log = new Log;
|
||||
}
|
||||
self::$db->delete( $this->tableName, ['ID', '>=', '0'] );
|
||||
self::$log->admin( 'Cleared Feedback' );
|
||||
Debug::info( 'Feedback Cleared' );
|
||||
return true;
|
||||
}
|
||||
}
|
60
app/plugins/feedback/plugin.php
Normal file
60
app/plugins/feedback/plugin.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/feedback/plugin.php
|
||||
*
|
||||
* This houses all of the main plugin info and functionality.
|
||||
*
|
||||
* @package TP Feedback
|
||||
* @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\Classes\Plugin;
|
||||
|
||||
class Feedback extends Plugin {
|
||||
public $pluginName = 'TP Feedback';
|
||||
public $pluginAuthor = 'JoeyK';
|
||||
public $pluginWebsite = 'https://TheTempusProject.com';
|
||||
public $modelVersion = '1.0';
|
||||
public $pluginVersion = '3.0';
|
||||
public $pluginDescription = 'A simple plugin which adds a form and management for user submitted feedback.';
|
||||
public $configName = 'feedback';
|
||||
public $configMatrix = [
|
||||
'enabled' => [
|
||||
'type' => 'radio',
|
||||
'pretty' => 'Enable User Feedback.',
|
||||
'default' => true,
|
||||
],
|
||||
'sendEmail' => [
|
||||
'type' => 'radio',
|
||||
'pretty' => 'Email the user after submitting.',
|
||||
'default' => false,
|
||||
],
|
||||
'emailTemplate' => [
|
||||
'type' => 'text',
|
||||
'pretty' => 'Email Template',
|
||||
'default' => 'feedbackEmail',
|
||||
],
|
||||
];
|
||||
public $permissionMatrix = [
|
||||
'feedback' => [
|
||||
'pretty' => 'Can Submit Feedback',
|
||||
'default' => false,
|
||||
],
|
||||
];
|
||||
public $footer_links = [
|
||||
[
|
||||
'text' => 'Feedback',
|
||||
'url' => '{ROOT_URL}feedback',
|
||||
],
|
||||
];
|
||||
public $admin_links = [
|
||||
[
|
||||
'text' => '<i class="fa fa-fw fa-support"></i> Feedback',
|
||||
'url' => '{ROOT_URL}admin/feedback',
|
||||
],
|
||||
];
|
||||
}
|
42
app/plugins/feedback/views/admin/list.html
Normal file
42
app/plugins/feedback/views/admin/list.html
Normal file
@ -0,0 +1,42 @@
|
||||
<legend>Feedback</legend>
|
||||
{PAGINATION}
|
||||
<form action="{ROOT_URL}admin/feedback/delete" method="post">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 5%">ID</th>
|
||||
<th style="width: 25%">Time</th>
|
||||
<th style="width: 55%">Feedback</th>
|
||||
<th style="width: 5%"></th>
|
||||
<th style="width: 5%"></th>
|
||||
<th style="width: 5%">
|
||||
<INPUT type="checkbox" onchange="checkAll(this)" name="check.f" value="F_[]"/>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{LOOP}
|
||||
<tr>
|
||||
<td>{ID}</td>
|
||||
<td>{DTC}{time}{/DTC}</td>
|
||||
<td>{feedback}</td>
|
||||
<td><a href="{ROOT_URL}admin/feedback/view/{ID}" class="btn btn-sm btn-primary" role="button"><i class="glyphicon glyphicon-open"></i></a></td>
|
||||
<td><a href="{ROOT_URL}admin/feedback/delete/{ID}" class="btn btn-sm btn-danger" role="button"><i class="glyphicon glyphicon-trash"></i></a></td>
|
||||
<td>
|
||||
<input type="checkbox" value="{ID}" name="F_[]">
|
||||
</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">Delete</button>
|
||||
</form>
|
||||
<br />
|
||||
<a href="{ROOT_URL}admin/feedback/clear">clear all</a>
|
56
app/plugins/feedback/views/admin/view.html
Normal file
56
app/plugins/feedback/views/admin/view.html
Normal file
@ -0,0 +1,56 @@
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xs-offset-0 col-sm-offset-0 col-md-offset-3 col-lg-offset-3 top-pad" >
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Feedback</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="row">
|
||||
<div class=" col-md-12 col-lg-12 ">
|
||||
<table class="table table-user-primary">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="left" width="200">ID:</td>
|
||||
<td align="right">{ID}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Time submitted:</td>
|
||||
<td align="right">{DTC}{time}{/DTC}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>IP:</td>
|
||||
<td align="right">{ip}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Email:</td>
|
||||
<td align="right">{email}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Name</td>
|
||||
<td align="right">{name}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" colspan="2">Feedback</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">{feedback}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-footer">
|
||||
{ADMIN}
|
||||
<form action="{ROOT_URL}admin/feedback/delete" method="post">
|
||||
<INPUT type="hidden" name="F_" value="{ID}"/>
|
||||
<input type="hidden" name="token" value="{TOKEN}" />
|
||||
<button name="submit" value="submit" type="submit" class="btn btn-sm btn-danger"><i class="glyphicon glyphicon-remove"></i></button>
|
||||
</form>
|
||||
{/ADMIN}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
27
app/plugins/feedback/views/feedback.html
Normal file
27
app/plugins/feedback/views/feedback.html
Normal file
@ -0,0 +1,27 @@
|
||||
<form action="" method="post" class="form-horizontal">
|
||||
<legend>Feedback</legend>
|
||||
<p>Here at {SITENAME} we highly value your feedback. We constantly strive to provide our users with the highest level of quality in everything we do.</p>
|
||||
<p>If you would like to provide any suggestions or comments on our service, we ask that you please fill out the quick form below and let us know what's on your mind.</p>
|
||||
<fieldset>
|
||||
<div class="form-group">
|
||||
<label for="name" class="col-lg-1 control-label">Name:</label>
|
||||
<div class="col-lg-2">
|
||||
<input class="form-control" type="text" name="name" id="name">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="feedbackEmail" class="col-lg-1 control-label">E-mail: (optional)</label>
|
||||
<div class="col-lg-2">
|
||||
<input class="form-control" type="text" name="feedbackEmail" id="feedbackEmail">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="entry" class="col-lg-3 control-label">Feedback:<br> (max:2000 characters)</label>
|
||||
<div class="col-lg-6">
|
||||
<textarea class="form-control" name="entry" maxlength="2000" rows="10" cols="50" id="entry"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<input type="hidden" name="token" value="{TOKEN}">
|
||||
<button name="submit" value="submit" type="submit" class="btn btn-lg btn-primary center-block">Submit</button><br>
|
||||
</form>
|
Reference in New Issue
Block a user