Initial commit
This commit is contained in:
113
app/plugins/messages/controllers/messages.php
Normal file
113
app/plugins/messages/controllers/messages.php
Normal file
@ -0,0 +1,113 @@
|
||||
<?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;
|
||||
|
||||
class Messages extends Controller {
|
||||
private static $message;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$title = 'Messages';
|
||||
self::$message = new Message;
|
||||
}
|
||||
|
||||
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() {
|
||||
Views::view( 'messages.inbox', self::$message->getInbox() );
|
||||
Views::view( 'messages.outbox', self::$message->getOutbox() );
|
||||
}
|
||||
|
||||
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 ) );
|
||||
}
|
||||
}
|
452
app/plugins/messages/models/message.php
Normal file
452
app/plugins/messages/models/message.php
Normal file
@ -0,0 +1,452 @@
|
||||
<?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\Canary as Debug;
|
||||
use TheTempusProject\Bedrock\Functions\Check;
|
||||
use TheTempusProject\Bedrock\Functions\Sanitize;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
use TheTempusProject\Bedrock\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( '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( '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;
|
||||
}
|
||||
}
|
59
app/plugins/messages/plugin.php
Normal file
59
app/plugins/messages/plugin.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?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 $configName = '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() {
|
||||
// This was taken directly from the main app
|
||||
// load the message template data as part of the template
|
||||
$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', '' );
|
||||
}
|
||||
if ( ! self::$loaded ) {
|
||||
App::$topNavRight .= '{RECENT_MESSAGES}';
|
||||
App::$topNavRightDropdown .= '<li><a href="{ROOT_URL}messages"><i class="fa fa-fw fa-envelope"></i> Inbox {MBADGE}</a></li>';
|
||||
self::$loaded = true;
|
||||
}
|
||||
parent::__construct();
|
||||
}
|
||||
}
|
1
app/plugins/messages/views/badge.html
Normal file
1
app/plugins/messages/views/badge.html
Normal file
@ -0,0 +1 @@
|
||||
<span class="label label-danger">{MESSAGE_COUNT}</span>
|
25
app/plugins/messages/views/create.html
Normal file
25
app/plugins/messages/views/create.html
Normal file
@ -0,0 +1,25 @@
|
||||
<form action="" method="post" class="form-horizontal">
|
||||
<legend>New Message</legend>
|
||||
<fieldset>
|
||||
<div class="form-group">
|
||||
<label for="toUser" class="col-lg-1 control-label">To:</label>
|
||||
<div class="col-lg-2">
|
||||
<input class="form-control" type="text" name="toUser" id="toUser" value="{prepopuser}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="subject" class="col-lg-1 control-label">Subject:</label>
|
||||
<div class="col-lg-2">
|
||||
<input class="form-control" type="text" name="subject" id="subject">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="entry" class="col-lg-3 control-label">Message:</label>
|
||||
<div class="col-lg-6">
|
||||
<textarea class="form-control" name="message" maxlength="2000" rows="10" cols="50" id="message"></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">Send</button><br>
|
||||
</form>
|
40
app/plugins/messages/views/inbox.html
Normal file
40
app/plugins/messages/views/inbox.html
Normal file
@ -0,0 +1,40 @@
|
||||
<h2>Inbox</h2>
|
||||
{PAGINATION}
|
||||
<form action="{ROOT_URL}messages/delete" method="post">
|
||||
<table class="table table-hover">
|
||||
<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>
|
43
app/plugins/messages/views/mesage.html
Normal file
43
app/plugins/messages/views/mesage.html
Normal file
@ -0,0 +1,43 @@
|
||||
<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">
|
||||
{LOOP}
|
||||
{SINGLE}
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">{subject}</h3>
|
||||
</div>
|
||||
{/SINGLE}
|
||||
<div class="panel-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="panel-footer">
|
||||
{ADMIN}
|
||||
{ID}
|
||||
<span class="pull-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>
|
43
app/plugins/messages/views/message.html
Normal file
43
app/plugins/messages/views/message.html
Normal file
@ -0,0 +1,43 @@
|
||||
<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">
|
||||
{LOOP}
|
||||
{SINGLE}
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">{subject}</h3>
|
||||
</div>
|
||||
{/SINGLE}
|
||||
<div class="panel-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="panel-footer">
|
||||
{ADMIN}
|
||||
{ID}
|
||||
<span class="pull-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>
|
41
app/plugins/messages/views/nav/recentMessagesDropdown.html
Normal file
41
app/plugins/messages/views/nav/recentMessagesDropdown.html
Normal file
@ -0,0 +1,41 @@
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="glyphicon glyphicon-envelope"></i>{MBADGE}</a>
|
||||
<ul class="dropdown-menu message-dropdown">
|
||||
<li class="message-header">
|
||||
<div class="media">
|
||||
<div class="media-body text-center" style="padding-bottom: 10px; padding-top: 10px">
|
||||
{MESSAGE_COUNT} unread message(s) total
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
{LOOP}
|
||||
<li class="message-preview">
|
||||
<a href="{ROOT_URL}messages/view/{ID}">
|
||||
<div class="media">
|
||||
<span class="pull-left">
|
||||
<img class="media-object avatar-round-40" src="{ROOT_URL}{fromAvatar}" alt="">
|
||||
</span>
|
||||
<div class="media-body">
|
||||
<h5 class="media-heading"><strong>{userFrom}</strong>
|
||||
</h5>
|
||||
<p class="small text-muted"><i class="fa fa-clock-o"></i> {DTC}{lastReply}{/DTC}</p>
|
||||
{summary}
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
{/LOOP}
|
||||
{ALT}
|
||||
<li class="message-preview">
|
||||
<div class="media">
|
||||
<div class="media-body text-center" style="padding-bottom: 10px; padding-top: 10px">
|
||||
<h5 class="media-heading"><strong>No Messages</strong></h5>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
{/ALT}
|
||||
<li class="message-footer text-center">
|
||||
<a href="{ROOT_URL}messages">Read All New Messages</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
38
app/plugins/messages/views/outbox.html
Normal file
38
app/plugins/messages/views/outbox.html
Normal file
@ -0,0 +1,38 @@
|
||||
<h2>Outbox</h2>
|
||||
{PAGINATION}
|
||||
<form action="{ROOT_URL}messages/delete" method="post">
|
||||
<table class="table table-hover">
|
||||
<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>
|
14
app/plugins/messages/views/reply.html
Normal file
14
app/plugins/messages/views/reply.html
Normal file
@ -0,0 +1,14 @@
|
||||
<form action="" method="post" class="form-horizontal">
|
||||
<legend>Reply</legend>
|
||||
<fieldset>
|
||||
<div class="form-group">
|
||||
<label for="message" class="col-lg-3 control-label">Message:</label>
|
||||
<div class="col-lg-6">
|
||||
<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}">
|
||||
<button name="submit" value="submit" type="submit" class="btn btn-lg btn-primary center-block">Send</button><br>
|
||||
</form>
|
1
app/plugins/messages/views/unreadBadge.html
Normal file
1
app/plugins/messages/views/unreadBadge.html
Normal file
@ -0,0 +1 @@
|
||||
class="bg-info"
|
Reference in New Issue
Block a user