hfkfhkfhgjkuhgfkjfghkj
This commit is contained in:
48
app/controllers/admin/admin.php
Executable file
48
app/controllers/admin/admin.php
Executable file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* app/controllers/admin/admin.php
|
||||
*
|
||||
* This is the admin log 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\Admin;
|
||||
|
||||
use TheTempusProject\Houdini\Classes\Issues;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\Classes\AdminController;
|
||||
use TheTempusProject\Models\Log;
|
||||
|
||||
class Admin extends AdminController {
|
||||
public static $log;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$title = 'Admin - Admin Logs';
|
||||
self::$log = new Log;
|
||||
}
|
||||
|
||||
public function delete( $id = null ) {
|
||||
if ( Input::exists( 'submit' ) ) {
|
||||
$id = Input::post( 'A_' );
|
||||
}
|
||||
if ( self::$log->delete( $id ) ) {
|
||||
Issues::add( 'success', 'Admin-log deleted' );
|
||||
} else {
|
||||
Issues::add( 'error', 'There was an error deleting log(s)' );
|
||||
}
|
||||
$this->index();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
return Views::view( 'admin.logs.admin_list', self::$log->list( 'admin' ) );
|
||||
}
|
||||
|
||||
public function view( $id = null ) {
|
||||
return Views::view( 'admin.logs.admin', self::$log->findById( $id ) );
|
||||
}
|
||||
}
|
64
app/controllers/admin/composer.php
Executable file
64
app/controllers/admin/composer.php
Executable file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* app/controllers/admin/composer.php
|
||||
*
|
||||
* This is the composer controller. Its only very effective when using composer for autoloading.
|
||||
*
|
||||
* @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\Views;
|
||||
use TheTempusProject\Houdini\Classes\Issues;
|
||||
use TheTempusProject\Classes\AdminController;
|
||||
use TheTempusProject\Classes\Installer;
|
||||
|
||||
class Composer extends AdminController {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$title = 'Admin - Composer Dependencies';
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$installer = new Installer;
|
||||
|
||||
// Files
|
||||
$composerJson = $installer->getComposerJson();
|
||||
if ( empty( $composerJson ) ) {
|
||||
return Issues::add( 'error', 'Composer json is missing.' );
|
||||
}
|
||||
$composerLock = $installer->getComposerLock();
|
||||
if ( empty( $composerLock ) ) {
|
||||
return Issues::add( 'error', 'Composer lock file is missing.' );
|
||||
}
|
||||
|
||||
// Required Packages
|
||||
$requiredPackages = $composerJson[ 'require' ];
|
||||
foreach ( $requiredPackages as $name => $version ) {
|
||||
$versionsRequired[ strtolower( $name ) ] = $version;
|
||||
}
|
||||
|
||||
// Installed Packages
|
||||
$installedPackages = $composerLock[ 'packages' ];
|
||||
foreach ( $installedPackages as $package ) {
|
||||
$name = strtolower( $package[ 'name' ] );
|
||||
$versionsInstalled[ $name ] = $package;
|
||||
}
|
||||
|
||||
// Versioning
|
||||
foreach ( $versionsInstalled as $package ) {
|
||||
$name = strtolower( $package[ 'name' ] );
|
||||
if ( !empty( $versionsRequired[ $name ] ) ) {
|
||||
$versionsInstalled[ $name ][ 'requiredVersion' ] = $versionsRequired[ $name ];
|
||||
} else {
|
||||
$versionsInstalled[ $name ][ 'requiredVersion' ] = 'sub-dependency';
|
||||
}
|
||||
$out[] = (object) $versionsInstalled[ $name ];
|
||||
}
|
||||
|
||||
Views::view( 'admin.modules.dependencies', $out );
|
||||
}
|
||||
}
|
54
app/controllers/admin/errors.php
Executable file
54
app/controllers/admin/errors.php
Executable file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* app/controllers/admin/errors.php
|
||||
*
|
||||
* This is the error logs 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\Admin;
|
||||
|
||||
use TheTempusProject\Houdini\Classes\Issues;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\Classes\AdminController;
|
||||
use TheTempusProject\Models\Log;
|
||||
|
||||
class Errors extends AdminController {
|
||||
public static $log;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$title = 'Admin - Error Logs';
|
||||
self::$log = new Log;
|
||||
}
|
||||
|
||||
public function delete( $id = null ) {
|
||||
if ( Input::exists( 'submit' ) ) {
|
||||
$id = Input::post( 'E_' );
|
||||
}
|
||||
if ( self::$log->delete( $id ) ) {
|
||||
Issues::add( 'success', 'Error-log deleted' );
|
||||
} else {
|
||||
Issues::add( 'error', 'There was an error deleting log(s)' );
|
||||
}
|
||||
$this->index();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
return Views::view( 'admin.logs.error_list', self::$log->list( 'error' ) );
|
||||
}
|
||||
|
||||
public function view( $id = null ) {
|
||||
return Views::view( 'admin.logs.error', self::$log->findById( $id ) );
|
||||
}
|
||||
|
||||
public function clear() {
|
||||
self::$log->clear( 'error' );
|
||||
Issues::add( 'success', 'Error Logs Cleared' );
|
||||
$this->index();
|
||||
}
|
||||
}
|
126
app/controllers/admin/groups.php
Executable file
126
app/controllers/admin/groups.php
Executable file
@ -0,0 +1,126 @@
|
||||
<?php
|
||||
/**
|
||||
* app/controllers/admin/groups.php
|
||||
*
|
||||
* This is the groups admin 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\Admin;
|
||||
|
||||
use TheTempusProject\Bedrock\Functions\Check;
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\Houdini\Classes\Navigation;
|
||||
use TheTempusProject\Houdini\Classes\Components;
|
||||
use TheTempusProject\Houdini\Classes\Issues;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Houdini\Classes\Forms;
|
||||
use TheTempusProject\Classes\AdminController;
|
||||
use TheTempusProject\Classes\Permissions;
|
||||
use TheTempusProject\Models\Group;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
|
||||
class Groups extends AdminController {
|
||||
public static $group;
|
||||
public static $permissions;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$title = 'Admin - Groups';
|
||||
self::$group = new Group;
|
||||
self::$permissions = new Permissions;
|
||||
}
|
||||
|
||||
public function create( $data = null ) {
|
||||
$perms = self::$group->getDefaultPermissions();
|
||||
if ( Input::exists( 'name' ) ) {
|
||||
$perms = self::$permissions->convertFormToArray();
|
||||
if ( self::$group->create( Input::post( 'name' ), $perms ) ) {
|
||||
Issues::add( 'success', 'Group created' );
|
||||
return $this->index();
|
||||
} else {
|
||||
Issues::add( 'error', 'There was an error creating your group.' );
|
||||
}
|
||||
}
|
||||
Components::set( 'PERMISSIONS_FORM', self::$permissions->getFormHtml( $perms ) );
|
||||
Views::view( 'admin.groups.create' );
|
||||
}
|
||||
|
||||
public function delete( $id = null ) {
|
||||
if ( Input::exists( 'submit' ) ) {
|
||||
$id = Input::post( 'G_' );
|
||||
}
|
||||
if ( self::$group->delete( $id ) ) {
|
||||
Issues::add( 'success', 'Group deleted' );
|
||||
} else {
|
||||
Issues::add( 'error', 'There was an error deleting group(s)' );
|
||||
}
|
||||
$this->index();
|
||||
}
|
||||
|
||||
public function edit( $data = null ) {
|
||||
$group = self::$group->findById( $data );
|
||||
if ( in_array( $group->name, self::$group::$protectedGroups ) ) {
|
||||
switch ( $group->name ) {
|
||||
case 'Super':
|
||||
if ( 'Super' !== App::$activeGroup->name ) {
|
||||
Issues::add( 'error', 'You do not have permission to do that.' );
|
||||
return $this->index();
|
||||
}
|
||||
case 'Admin':
|
||||
if ( 'Moderator' === App::$activeGroup->name ) {
|
||||
Issues::add( 'error', 'You do not have permission to do that.' );
|
||||
return $this->index();
|
||||
}
|
||||
}
|
||||
}
|
||||
$perms = $group->perms;
|
||||
if ( Input::exists( 'name' ) ) {
|
||||
$perms = self::$permissions->convertFormToArray();
|
||||
// @ todo need to come up with a way to check these forms....
|
||||
if ( self::$group->update( $data, Input::post( 'name' ), $perms ) ) {
|
||||
Issues::add( 'success', 'Group updated' );
|
||||
return $this->index();
|
||||
} else {
|
||||
Issues::add( 'error', 'There was an error with your request.' );
|
||||
}
|
||||
}
|
||||
Components::set( 'PERMISSIONS_FORM', self::$permissions->getFormHtml( $perms ) );
|
||||
Views::view( 'admin.groups.edit', $group );
|
||||
}
|
||||
|
||||
public function index( $data = null ) {
|
||||
Views::view( 'admin.groups.list', self::$group->listPaginated() );
|
||||
}
|
||||
|
||||
public function listmembers( $data = null ) {
|
||||
$groupData = self::$group->findById( $data );
|
||||
if ( $groupData !== false ) {
|
||||
Components::set( 'groupName', $groupData->name );
|
||||
return Views::view( 'admin.groups.list_members', self::$group->listMembers( $groupData->ID ) );
|
||||
}
|
||||
Issues::add( 'error', 'Group not found' );
|
||||
$this->index();
|
||||
}
|
||||
|
||||
public function view( $data = null ) {
|
||||
$groupData = self::$group->findById( $data );
|
||||
if ( $groupData == false ) {
|
||||
Issues::add( 'error', 'Group not found' );
|
||||
return $this->index();
|
||||
}
|
||||
$out = '';
|
||||
foreach ( self::$group->getDefaultPermissions() as $name => $default ) {
|
||||
$node_name = $name . '_pretty';
|
||||
$pretty_name = $groupData->$node_name;
|
||||
$node_name2 = $name . '_text';
|
||||
$pretty_value = $groupData->$node_name2;
|
||||
$out .= '<tr><td>' . $pretty_name . '</td><td>' . $pretty_value . '</td></tr>';
|
||||
}
|
||||
Components::set( 'PERMISSIONS_ROWS', $out );
|
||||
Views::view( 'admin.groups.view', $groupData );
|
||||
}
|
||||
}
|
88
app/controllers/admin/home.php
Executable file
88
app/controllers/admin/home.php
Executable file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* app/controllers/admin/home.php
|
||||
*
|
||||
* This is the admin dashboard 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\Admin;
|
||||
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Houdini\Classes\Components;
|
||||
use TheTempusProject\Classes\AdminController;
|
||||
use TheTempusProject\Models\User;
|
||||
use TheTempusProject\Models\Comments;
|
||||
use TheTempusProject\Models\Posts;
|
||||
use TheTempusProject\Models\Contact;
|
||||
use TheTempusProject\Plugins\Comments as CommentPlugin;
|
||||
use TheTempusProject\Plugins\Blog as BlogPlugin;
|
||||
use TheTempusProject\Plugins\Contact as ContactPlugin;
|
||||
use TheTempusProject\Canary\Bin\Canary as Debug;
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
|
||||
class Home extends AdminController {
|
||||
public static $user;
|
||||
public static $comments;
|
||||
public static $posts;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$title = 'Admin - Home';
|
||||
}
|
||||
|
||||
public function index() {
|
||||
Components::set( 'commentDash', '' );
|
||||
if ( class_exists( 'TheTempusProject\Plugins\Comments' ) ) {
|
||||
$plugin = new CommentPlugin;
|
||||
|
||||
if ( ! $plugin->checkEnabled() ) {
|
||||
Debug::info( 'Comments Plugin is disabled in the control panel.' );
|
||||
} else {
|
||||
$comments = new Comments;
|
||||
$commentList = Views::simpleView( 'comments.admin.dashboard', $comments->recent( 'all', 5 ) );
|
||||
Components::set( 'commentDash', $commentList );
|
||||
}
|
||||
}
|
||||
|
||||
if ( class_exists( 'TheTempusProject\Plugins\Blog' ) ) {
|
||||
$plugin = new BlogPlugin;
|
||||
|
||||
if ( ! $plugin->checkEnabled() ) {
|
||||
Debug::info( 'Blog Plugin is disabled in the control panel.' );
|
||||
Components::set( 'blogDash', '' );
|
||||
} else {
|
||||
$posts = new Posts;
|
||||
$postsList = Views::simpleView( 'blog.admin.dashboard', $posts->recent( 5 ) );
|
||||
Components::set( 'blogDash', $postsList );
|
||||
}
|
||||
}
|
||||
|
||||
if ( class_exists( 'TheTempusProject\Plugins\Contact' ) ) {
|
||||
$plugin = new ContactPlugin;
|
||||
|
||||
if ( ! $plugin->checkEnabled() ) {
|
||||
Debug::info( 'Contact Plugin is disabled in the control panel.' );
|
||||
Components::set( 'contactDash', '' );
|
||||
} else {
|
||||
$posts = new Contact;
|
||||
$postsList = Views::simpleView( 'contact.admin.dashboard', $posts->listPaginated( 5 ) );
|
||||
Components::set( 'contactDash', $postsList );
|
||||
}
|
||||
}
|
||||
|
||||
self::$user = new User;
|
||||
$users = Views::simpleView( 'admin.dashboard.users', self::$user->recent( 5 ) );
|
||||
Components::set( 'userDash', $users );
|
||||
|
||||
if ( Input::exists( 'submit' ) ) {
|
||||
$results = Views::simpleView( 'admin.dashboard.users', self::$user->search( Input::post('searchTerm') ) );
|
||||
Components::set( 'searchResults', $results );
|
||||
}
|
||||
|
||||
Views::view( 'admin.dashboard.dash' );
|
||||
}
|
||||
}
|
368
app/controllers/admin/images.php
Normal file
368
app/controllers/admin/images.php
Normal file
@ -0,0 +1,368 @@
|
||||
<?php
|
||||
/**
|
||||
* app/controllers/admin/tokens.php
|
||||
*
|
||||
* This is the admin app/user tokens 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\Admin;
|
||||
|
||||
use TheTempusProject\Classes\Forms as TTPForms;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Houdini\Classes\Issues;
|
||||
use TheTempusProject\Houdini\Classes\Navigation;
|
||||
use TheTempusProject\Houdini\Classes\Components;
|
||||
use TheTempusProject\Houdini\Classes\Forms;
|
||||
use TheTempusProject\Classes\AdminController;
|
||||
use TheTempusProject\Models\Token;
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\Bedrock\Functions\Check;
|
||||
use TheTempusProject\Hermes\Functions\Redirect;
|
||||
use TheTempusProject\Bedrock\Functions\Session;
|
||||
use TheTempusProject\Hermes\Functions\Route as Routes;
|
||||
use TheTempusProject\Bedrock\Functions\Upload;
|
||||
use RecursiveIteratorIterator;
|
||||
use RecursiveDirectoryIterator;
|
||||
use FilesystemIterator;
|
||||
|
||||
class Images extends AdminController {
|
||||
private $directories = [
|
||||
APP_ROOT_DIRECTORY . 'images',
|
||||
APP_ROOT_DIRECTORY . 'app/images',
|
||||
APP_ROOT_DIRECTORY . 'app/plugins'
|
||||
];
|
||||
|
||||
private $excludedDirectories = [
|
||||
'.',
|
||||
'..',
|
||||
'vendor',
|
||||
'docker',
|
||||
'logs',
|
||||
'gitlab',
|
||||
'uploads',
|
||||
'config',
|
||||
];
|
||||
|
||||
public function upload() {
|
||||
if ( Input::exists( 'submit' ) ) {
|
||||
$route = '';
|
||||
$destination = '';
|
||||
if ( !TTPForms::check( 'addImage' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your image upload.' => Check::userErrors() ] );
|
||||
} else {
|
||||
$folder = Input::post( 'folderSelect' ) . DIRECTORY_SEPARATOR;
|
||||
// dv( $folder );
|
||||
$upload = Upload::image( 'uploadImage', $folder );
|
||||
if ( $upload ) {
|
||||
$route = str_replace( APP_ROOT_DIRECTORY, '', $folder );
|
||||
$destination = $route . Upload::last();
|
||||
Issues::add( 'success', 'Image uploaded.' );
|
||||
} else {
|
||||
Issues::add( 'error', [ 'There was an error with your image upload.' => Check::userErrors() ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$folders = $this->getDirectoriesRecursive( APP_ROOT_DIRECTORY );
|
||||
$folderHtml = $this->generateFolderHtml( $folders );
|
||||
Components::set( 'FOLDER_SELECT_ROOT', APP_ROOT_DIRECTORY );
|
||||
Components::set( 'FOLDER_SELECT', Views::simpleView( 'forms.folderSelect', $folderHtml ) );
|
||||
Views::view( 'admin.images.upload' );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private function getFolderObject( $folder, $subdirs = '' ) {
|
||||
$names = explode( DIRECTORY_SEPARATOR, $folder );
|
||||
$folderName = array_pop( $names );
|
||||
$out = [
|
||||
'folderName' => $folderName,
|
||||
'location' => $folder,
|
||||
'subdirs' => $subdirs,
|
||||
];
|
||||
if ( ! empty( $subdirs ) ) {
|
||||
$out['folderexpand'] = '<i class="fa-solid fa-caret-down justify-content-end"></i>';
|
||||
} else {
|
||||
$out['folderexpand'] = '';
|
||||
}
|
||||
return (object) $out;
|
||||
}
|
||||
|
||||
private function generateFolderHtml( $folders ) {
|
||||
$rows = [];
|
||||
foreach ( $folders as $top => $sub ) {
|
||||
$object = $this->getFolderObject( $top );
|
||||
if ( $top == $sub ) {
|
||||
$html = '';
|
||||
} else {
|
||||
$children = $this->generateFolderHtml( $sub );
|
||||
Components::set( 'parentfolderName', $object->folderName );
|
||||
$html = Views::simpleView( 'forms.folderSelectParent', $children );
|
||||
Components::set( 'parentfolderName', '' );
|
||||
}
|
||||
$rows[] = $this->getFolderObject( $top, $html );
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
private function getDirectoriesRecursive( $directory ) {
|
||||
$dirs = [];
|
||||
|
||||
$directory = rtrim( $directory, DIRECTORY_SEPARATOR );
|
||||
$directory = $directory. DIRECTORY_SEPARATOR;
|
||||
|
||||
$files = scandir( $directory );
|
||||
$filteredFiles = array_values( array_diff( $files, $this->excludedDirectories ) );
|
||||
|
||||
foreach ( $filteredFiles as $key => $filename ) {
|
||||
$long_name = $directory . $filename;
|
||||
$is_dir = ( ( strpos( $filename, '.' ) === false ) && ( is_dir( $long_name ) === true ) );
|
||||
if ( $is_dir ) {
|
||||
$recursive_dirs = $this->getDirectoriesRecursive( $long_name );
|
||||
if ( empty( $recursive_dirs ) ) {
|
||||
$recursive_dirs = $long_name;
|
||||
}
|
||||
$dirs[$long_name] = $recursive_dirs;
|
||||
}
|
||||
}
|
||||
|
||||
return $dirs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$title = 'Admin - Images';
|
||||
}
|
||||
|
||||
public function create() {
|
||||
if ( Input::exists( 'submit' ) ) {
|
||||
if ( !TTPForms::check( 'addImage' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your image.' => Check::userErrors() ] );
|
||||
}
|
||||
|
||||
if ( Input::exists( 'folder' ) ) {
|
||||
$folder = Input::post('folder');
|
||||
} else {
|
||||
// IMAGE_DIRECTORY
|
||||
$folder = UPLOAD_DIRECTORY . App::$activeUser->username . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
$upload = Upload::image( 'upload', $folder );
|
||||
|
||||
if ( $upload ) {
|
||||
$route = str_replace( APP_ROOT_DIRECTORY, '', $folder );
|
||||
$out = $route . Upload::last();
|
||||
} else {
|
||||
Debug::error( 'There was an error with your upload.');
|
||||
Issues::add( 'error', [ 'There was an error with your upload.' => Check::userErrors() ] );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// if ( self::$token->create(
|
||||
// Input::post( 'name' ),
|
||||
// Input::post( 'notes' ),
|
||||
// Input::post( 'token_type' )
|
||||
// ) ) {
|
||||
// Session::flash( 'success', 'Token Created' );
|
||||
// Redirect::to( 'admin/images' );
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
Views::view( 'admin.images.create' );
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
if ( self::$token->delete( [ $id ] ) ) {
|
||||
Session::flash( 'success', 'Token deleted.' );
|
||||
}
|
||||
Redirect::to( 'admin/images' );
|
||||
}
|
||||
|
||||
public function rename() {
|
||||
|
||||
if ( ! Input::exists( 'fileLocation' ) ) {
|
||||
Session::flash( 'warning', 'Unknown image.' );
|
||||
Redirect::to( 'admin/images' );
|
||||
}
|
||||
|
||||
Components::set( 'filelocation', Input::get( 'fileLocation' ) );
|
||||
|
||||
if ( Input::exists( 'submit' ) ) {
|
||||
if ( !TTPForms::check( 'renameIImage' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error renaming the image.' => Check::userErrors() ] );
|
||||
} else {
|
||||
$result = $this->renameFile( Input::post( 'filelocation' ), Input::post( 'newname' ) );
|
||||
|
||||
if ( ! empty( $result ) ) {
|
||||
Session::flash( 'success', 'Image has been renamed.' );
|
||||
Redirect::to( 'admin/images' );
|
||||
} else {
|
||||
Issues::add( 'error', [ 'There was an error with the install.' => $this->installer->getErrors() ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Views::view( 'admin.images.rename' );
|
||||
}
|
||||
|
||||
public function index() {
|
||||
return Views::view( 'admin.images.list.combined', $this->getAllImageDetails() );
|
||||
}
|
||||
|
||||
public function view() {
|
||||
if ( Input::exists( 'fileLocation' ) ) {
|
||||
return Views::view( 'admin.images.view', $this->getImageByLocation( Input::get( 'fileLocation' ) ) );
|
||||
}
|
||||
return $this->index();
|
||||
}
|
||||
|
||||
private function getAllImages() {
|
||||
$files = [];
|
||||
foreach ($this->directories as $dir) {
|
||||
if ($dir === 'app/plugins') {
|
||||
$pluginDirs = glob($dir . '/*', GLOB_ONLYDIR);
|
||||
foreach ($pluginDirs as $pluginDir) {
|
||||
$imageDir = $pluginDir . '/images';
|
||||
if (is_dir($imageDir)) {
|
||||
$files = array_merge($files, $this->scanDirectoryRecursively($imageDir));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$files = array_merge($files, $this->scanDirectory($dir));
|
||||
}
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
|
||||
private function scanDirectory($path) {
|
||||
return glob($path . '/*.{jpg,jpeg,png,gif,webp}', GLOB_BRACE) ?: [];
|
||||
}
|
||||
|
||||
private function scanDirectoryRecursively($path) {
|
||||
$files = [];
|
||||
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS));
|
||||
|
||||
foreach ($iterator as $file) {
|
||||
if (preg_match('/\.(jpg|jpeg|png|gif|webp)$/i', $file->getFilename())) {
|
||||
$files[] = $file->getPathname();
|
||||
}
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
private function getAllImageDetails() {
|
||||
$images = [];
|
||||
$files = $this->getAllImages();
|
||||
foreach ( $files as $file ) {
|
||||
$images[] = $this->getImageByLocation( $file );
|
||||
}
|
||||
return $images;
|
||||
}
|
||||
|
||||
private function getImageByLocation( $location ) {
|
||||
$realPath = realpath( $location );
|
||||
|
||||
return (object) [
|
||||
'filename' => basename( $location ),
|
||||
'extension' => pathinfo( $location , PATHINFO_EXTENSION),
|
||||
'fileSize' => $this->formatFileSize(filesize( $location )),
|
||||
'location' => $realPath,
|
||||
'locationSafe' => urlencode( $realPath ),
|
||||
'url' => Routes::getAddress() . str_replace( APP_ROOT_DIRECTORY, '', $realPath ),
|
||||
'folder' => dirname( $location )
|
||||
];
|
||||
}
|
||||
|
||||
private function formatFileSize($size) {
|
||||
$units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||
$i = 0;
|
||||
while ($size >= 1024 && $i < count($units) - 1) {
|
||||
$size /= 1024;
|
||||
$i++;
|
||||
}
|
||||
return round($size, 2) . ' ' . $units[$i];
|
||||
}
|
||||
|
||||
private function renameFile( $currentLocation, $newFilename ) {
|
||||
// Ensure the file exists
|
||||
if (!file_exists($currentLocation)) {
|
||||
throw new \Exception("File does not exist: $currentLocation");
|
||||
}
|
||||
|
||||
// Extract directory and current extension
|
||||
$directory = dirname($currentLocation);
|
||||
$currentExtension = pathinfo($currentLocation, PATHINFO_EXTENSION);
|
||||
$newExtension = pathinfo($newFilename, PATHINFO_EXTENSION);
|
||||
|
||||
// Ensure the file extension has not changed
|
||||
if (strcasecmp($currentExtension, $newExtension) !== 0) {
|
||||
throw new \Exception("File extension cannot be changed.");
|
||||
}
|
||||
|
||||
// Construct the new file path
|
||||
$newLocation = $directory . DIRECTORY_SEPARATOR . $newFilename;
|
||||
|
||||
// Ensure the new file name does not already exist
|
||||
if (file_exists($newLocation)) {
|
||||
throw new \Exception("A file with the new name already exists: $newFilename");
|
||||
}
|
||||
|
||||
// Attempt to rename the file
|
||||
if (!rename($currentLocation, $newLocation)) {
|
||||
throw new \Exception("Failed to rename file.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
54
app/controllers/admin/logins.php
Executable file
54
app/controllers/admin/logins.php
Executable file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* app/controllers/admin/logins.php
|
||||
*
|
||||
* This is the login logs 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\Admin;
|
||||
|
||||
use TheTempusProject\Houdini\Classes\Issues;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\Classes\AdminController;
|
||||
use TheTempusProject\Models\Log;
|
||||
|
||||
class Logins extends AdminController {
|
||||
public static $log;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$title = 'Admin - Login Logs';
|
||||
self::$log = new Log;
|
||||
}
|
||||
|
||||
public function delete( $id = null ) {
|
||||
if ( Input::exists( 'submit' ) ) {
|
||||
$id = Input::post( 'L_' );
|
||||
}
|
||||
if ( self::$log->delete( $id ) ) {
|
||||
Issues::add( 'success', 'Login-log deleted' );
|
||||
} else {
|
||||
Issues::add( 'error', 'There was an error deleting log(s)' );
|
||||
}
|
||||
$this->index();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
return Views::view( 'admin.logs.login_list', self::$log->list( 'login' ) );
|
||||
}
|
||||
|
||||
public function view( $id = null ) {
|
||||
return Views::view( 'admin.logs.login', self::$log->findById( $id ) );
|
||||
}
|
||||
|
||||
public function clear() {
|
||||
self::$log->clear( 'login' );
|
||||
Issues::add( 'success', 'Login Logs Cleared' );
|
||||
$this->index();
|
||||
}
|
||||
}
|
33
app/controllers/admin/logs.php
Executable file
33
app/controllers/admin/logs.php
Executable file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* app/controllers/admin/logs.php
|
||||
*
|
||||
* This is the generic logs 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\Admin;
|
||||
|
||||
use TheTempusProject\Houdini\Classes\Issues;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Classes\AdminController;
|
||||
use TheTempusProject\Models\Log;
|
||||
|
||||
class Logs extends AdminController {
|
||||
public static $log;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$title = 'Admin - Logs';
|
||||
self::$log = new Log;
|
||||
}
|
||||
|
||||
public function index( $data = null ) {
|
||||
Views::view( 'admin.logs.error_list', self::$log->list( 'error' ) );
|
||||
Views::view( 'admin.logs.admin_list', self::$log->list( 'admin' ) );
|
||||
Views::view( 'admin.logs.login_list', self::$log->list( 'login' ) );
|
||||
}
|
||||
}
|
136
app/controllers/admin/plugins.php
Executable file
136
app/controllers/admin/plugins.php
Executable file
@ -0,0 +1,136 @@
|
||||
<?php
|
||||
/**
|
||||
* app/controllers/admin/installed.php
|
||||
*
|
||||
* This is the installed plugins 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\Admin;
|
||||
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Houdini\Classes\Components;
|
||||
use TheTempusProject\Houdini\Classes\Navigation;
|
||||
use TheTempusProject\Classes\AdminController;
|
||||
use TheTempusProject\Classes\Installer;
|
||||
use TheTempusProject\Classes\Plugin;
|
||||
use TheTempusProject\Hermes\Functions\Redirect;
|
||||
use TheTempusProject\Bedrock\Functions\Session;
|
||||
|
||||
class Plugins extends AdminController {
|
||||
public $installer;
|
||||
public $plugins;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$title = 'Admin - Installed Plugins';
|
||||
$this->installer = new Installer;
|
||||
$this->plugins = $this->installer->getAvailablePlugins();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
Views::view( 'admin.modules.plugins.list', $this->plugins );
|
||||
}
|
||||
|
||||
public function disable( $name = null ) {
|
||||
if ( empty( $name ) ) {
|
||||
Session::flash( 'error', 'Unknown Plugin.' );
|
||||
Redirect::to( 'admin/plugins' );
|
||||
}
|
||||
Components::set( 'PLUGIN', $name );
|
||||
self::$title = 'Admin - Disable ' . $name;
|
||||
if ( !Input::exists( 'installHash' ) ) {
|
||||
return Views::view( 'admin.modules.plugins.disable' );
|
||||
}
|
||||
if ( !Plugin::disable( $name ) ) {
|
||||
Session::flash( 'error', 'There was an error disabling the plugin.' );
|
||||
} else {
|
||||
Session::flash( 'success', 'Plugin has been disabled.' );
|
||||
}
|
||||
Redirect::to( 'admin/plugins' );
|
||||
}
|
||||
|
||||
public function enable( $name = null ) {
|
||||
if ( empty( $name ) ) {
|
||||
Session::flash( 'error', 'Unknown Plugin.' );
|
||||
Redirect::to( 'admin/plugins' );
|
||||
}
|
||||
Components::set( 'PLUGIN', $name );
|
||||
self::$title = 'Admin - Enable ' . $name;
|
||||
if ( !Input::exists( 'installHash' ) ) {
|
||||
return Views::view( 'admin.modules.plugins.enable' );
|
||||
}
|
||||
if ( ! Plugin::enable( $name ) ) {
|
||||
Session::flash( 'error', 'There was an error enabling the plugin.' );
|
||||
} else {
|
||||
Session::flash( 'success', 'Plugin has been enabled.' );
|
||||
}
|
||||
Redirect::to( 'admin/plugins' );
|
||||
}
|
||||
|
||||
public function install( $name = null ) {
|
||||
if ( empty( $name ) ) {
|
||||
Session::flash( 'error', 'Unknown Plugin.' );
|
||||
Redirect::to( 'admin/plugins' );
|
||||
}
|
||||
$name = strtolower( $name );
|
||||
Components::set( 'PLUGIN', $name );
|
||||
self::$title = 'Admin - Install ' . $name;
|
||||
if ( ! Input::exists( 'installHash' ) ) {
|
||||
return Views::view( 'admin.modules.plugins.install' );
|
||||
}
|
||||
|
||||
if ( empty( $this->plugins[$name] ) ) {
|
||||
Session::flash( 'error', 'Unknown Plugin.' );
|
||||
} else {
|
||||
$result = $this->installer->installPlugin( $this->plugins[$name] );
|
||||
if ( empty( $result ) ) {
|
||||
Session::flash( 'error', [ 'There was an error with the install.' => $this->installer->getErrors() ] );
|
||||
} else {
|
||||
Session::flash( 'success', 'Plugin has been installed.' );
|
||||
}
|
||||
}
|
||||
Redirect::to( 'admin/plugins' );
|
||||
}
|
||||
|
||||
public function uninstall( $name = null ) {
|
||||
if ( empty($name)) {
|
||||
Session::flash( 'error', 'Unknown Plugin.' );
|
||||
Redirect::to( 'admin/plugins' );
|
||||
}
|
||||
$name = strtolower($name);
|
||||
Components::set( 'PLUGIN', $name );
|
||||
self::$title = 'Admin - Uninstall ' . $name;
|
||||
|
||||
if ( !Input::exists( 'uninstallHash' ) ) {
|
||||
return Views::view( 'admin.modules.plugins.uninstall' );
|
||||
}
|
||||
|
||||
if ( empty( $this->plugins[$name] ) ) {
|
||||
Session::flash( 'error', 'Unknown Plugin.' );
|
||||
} else {
|
||||
$result = $this->installer->uninstallPlugin( $this->plugins[$name] );
|
||||
if ( empty($result) ) {
|
||||
Session::flash( 'error', [ 'There was an error with the uninstall.' => $this->installer->getErrors() ] );
|
||||
} else {
|
||||
Session::flash( 'success', 'Plugin has been uninstalled.' );
|
||||
}
|
||||
}
|
||||
Redirect::to( 'admin/plugins' );
|
||||
}
|
||||
|
||||
public function view( $name = null ) {
|
||||
$name = strtolower($name);
|
||||
|
||||
if ( empty( $this->plugins[$name] ) ) {
|
||||
Session::flash( 'error', 'Unknown Plugin.' );
|
||||
Redirect::to( 'admin/plugins' );
|
||||
} else {
|
||||
Views::view( 'admin.modules.plugins.view', $this->plugins[$name] );
|
||||
}
|
||||
}
|
||||
}
|
101
app/controllers/admin/routes.php
Executable file
101
app/controllers/admin/routes.php
Executable file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/**
|
||||
* app/controllers/admin/routes.php
|
||||
*
|
||||
* This is the admin routes/redirects 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\Admin;
|
||||
|
||||
use TheTempusProject\Classes\Forms as TTPForms;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Houdini\Classes\Issues;
|
||||
use TheTempusProject\Houdini\Classes\Navigation;
|
||||
use TheTempusProject\Houdini\Classes\Components;
|
||||
use TheTempusProject\Houdini\Classes\Forms;
|
||||
use TheTempusProject\Classes\AdminController;
|
||||
use TheTempusProject\Models\Routes as RoutesClass;
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\Bedrock\Functions\Check;
|
||||
use TheTempusProject\Hermes\Functions\Redirect;
|
||||
use TheTempusProject\Bedrock\Functions\Session;
|
||||
|
||||
class Routes extends AdminController {
|
||||
public static $routes;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$title = 'Admin - Redirects';
|
||||
self::$routes = new RoutesClass;
|
||||
}
|
||||
|
||||
public function create() {
|
||||
if ( ! Input::exists( 'redirect_type' ) ) {
|
||||
return Views::view( 'admin.routes.create' );
|
||||
}
|
||||
|
||||
if ( !TTPForms::check( 'createRoute' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your route.' => Check::userErrors() ] );
|
||||
return Views::view( 'admin.routes.create' );
|
||||
}
|
||||
|
||||
if ( self::$routes->create(
|
||||
Input::post( 'original_url' ),
|
||||
Input::post( 'forwarded_url' ),
|
||||
Input::post( 'nickname' ),
|
||||
Input::post( 'redirect_type' )
|
||||
) ) {
|
||||
Session::flash( 'success', 'Route Created' );
|
||||
Redirect::to( 'admin/routes' );
|
||||
}
|
||||
|
||||
Issues::add( 'error', 'There was an unknown error saving your redirect.' );
|
||||
Views::view( 'admin.routes.create' );
|
||||
}
|
||||
|
||||
public function delete( $id = null ) {
|
||||
if ( Input::exists( 'submit' ) ) {
|
||||
$id = Input::post( 'R_' );
|
||||
}
|
||||
if ( self::$routes->delete( [ $id ] ) ) {
|
||||
Session::flash( 'success', 'Route(s) deleted.' );
|
||||
} else {
|
||||
Session::flash( 'error', 'There was an error with your request.' );
|
||||
}
|
||||
Redirect::to( 'admin/routes' );
|
||||
}
|
||||
|
||||
public function edit( $id = null ) {
|
||||
$route = self::$routes->findById( $id );
|
||||
if ( Input::exists( 'redirect_type' ) ) {
|
||||
if ( !TTPForms::check( 'editRoute' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your route.' => Check::userErrors() ] );
|
||||
} else {
|
||||
if ( self::$routes->update(
|
||||
$id,
|
||||
Input::post( 'original_url' ),
|
||||
Input::post( 'forwarded_url' ),
|
||||
Input::post( 'nickname' ),
|
||||
Input::post( 'redirect_type' )
|
||||
) ) {
|
||||
Session::flash( 'success', 'Route Updated' );
|
||||
Redirect::to( 'admin/routes' );
|
||||
}
|
||||
}
|
||||
}
|
||||
Forms::selectOption( $route->redirect_type );
|
||||
return Views::view( 'admin.routes.edit', $route );
|
||||
}
|
||||
|
||||
public function index() {
|
||||
return Views::view( 'admin.routes.list', self::$routes->listPaginated() );
|
||||
}
|
||||
|
||||
public function view( $id = null ) {
|
||||
return Views::view( 'admin.routes.view', self::$routes->findById( $id ) );
|
||||
}
|
||||
}
|
109
app/controllers/admin/send_mail.php
Executable file
109
app/controllers/admin/send_mail.php
Executable file
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* app/controllers/admin/send_mail.php
|
||||
*
|
||||
* This is the admin email controller. The only real use is to send out emails to the various lists.
|
||||
*
|
||||
* @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\Classes\Email;
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\Houdini\Classes\Issues;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Models\User;
|
||||
use TheTempusProject\Models\Subscribe;
|
||||
use TheTempusProject\Plugins\Subscribe as Plugin;
|
||||
|
||||
class SendMail extends AdminController {
|
||||
public static $user;
|
||||
public static $subscribe;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$title = 'Admin - Send Mail';
|
||||
self::$user = new User;
|
||||
|
||||
if ( class_exists( 'TheTempusProject\Plugins\Subscribe' ) ) {
|
||||
$plugin = new Plugin;
|
||||
if ( ! $plugin->checkEnabled() ) {
|
||||
Issues::add( 'notice', 'Subscriptions are disabled so those feature will be unavailable.' );
|
||||
} else {
|
||||
self::$subscribe = new Subscribe;
|
||||
}
|
||||
} else {
|
||||
Issues::add( 'notice', 'Subscriptions plugin is not installed so those feature will be unavailable.' );
|
||||
}
|
||||
}
|
||||
|
||||
private function emailSubscribers( $params ) {
|
||||
if ( empty( self::$subscribe ) ) {
|
||||
Issues::add( 'error', 'Subscriptions plugin is unavailable' );
|
||||
return;
|
||||
}
|
||||
$list = self::$subscribe->list();
|
||||
if ( empty( $list ) ) {
|
||||
Issues::add( 'error', 'No subscribers found' );
|
||||
return;
|
||||
}
|
||||
foreach ( $list as $recipient ) {
|
||||
$params[ 'confirmationCode' ] = $recipient->confirmationCode;
|
||||
Email::send( $recipient->email, 'contact', $params, [ 'template' => true, 'unsubscribe' => true ] );
|
||||
}
|
||||
}
|
||||
|
||||
private function emailUsers( $params, $limit = null ) {
|
||||
$list = self::$user->userList( $limit );
|
||||
foreach ( $list as $recipient ) {
|
||||
Email::send( $recipient->email, 'contact', $params, [ 'template' => true ] );
|
||||
}
|
||||
}
|
||||
|
||||
public function index() {
|
||||
if ( Input::exists( 'mailType' ) ) {
|
||||
$params = [
|
||||
'subject' => Input::post( 'mailSubject' ),
|
||||
'title' => Input::post( 'mailTitle' ),
|
||||
'message' => Input::post( 'mailMessage' ),
|
||||
];
|
||||
switch ( Input::post( 'mailType' ) ) {
|
||||
case 'registered':
|
||||
$this->emailUsers( $params );
|
||||
Issues::add( 'success', 'Email(s) Sent' );
|
||||
break;
|
||||
|
||||
case 'newsletter':
|
||||
$this->emailUsers( $params, 'newsletter' );
|
||||
Issues::add( 'success', 'Email(s) Sent' );
|
||||
break;
|
||||
|
||||
case 'all':
|
||||
$this->emailUsers( $params );
|
||||
$this->emailSubscribers( $params );
|
||||
Issues::add( 'success', 'Email(s) Sent' );
|
||||
break;
|
||||
|
||||
case 'opt':
|
||||
$this->emailUsers( $params, 'newsletter' );
|
||||
$this->emailSubscribers( $params );
|
||||
Issues::add( 'success', 'Email(s) Sent' );
|
||||
break;
|
||||
|
||||
case 'subscribers':
|
||||
$this->emailSubscribers( $params );
|
||||
Issues::add( 'success', 'Email(s) Sent' );
|
||||
break;
|
||||
|
||||
default:
|
||||
Issues::add( 'error', 'Invalid Request' );
|
||||
break;
|
||||
}
|
||||
}
|
||||
Views::view( 'admin.contact' );
|
||||
}
|
||||
}
|
48
app/controllers/admin/settings.php
Executable file
48
app/controllers/admin/settings.php
Executable file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* app/controllers/admin/settings.php
|
||||
*
|
||||
* This is the configuration and settings 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\Admin;
|
||||
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\Houdini\Classes\Components;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Houdini\Classes\Issues;
|
||||
use TheTempusProject\Houdini\Classes\Forms;
|
||||
use TheTempusProject\Classes\AdminController;
|
||||
use TheTempusProject\Models\Group;
|
||||
use TheTempusProject\Classes\Config;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
|
||||
class Settings extends AdminController {
|
||||
public static $group;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$title = 'Admin - Settings';
|
||||
self::$group = new Group;
|
||||
}
|
||||
|
||||
public function index() {
|
||||
if ( Input::exists( 'submit' ) ) {
|
||||
if ( !App::$activeConfig->updateFromForm( true ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your request.' => Check::userErrors() ] );
|
||||
} else {
|
||||
Issues::add( 'success', 'Settings Updated' );
|
||||
}
|
||||
}
|
||||
Components::set( 'configForm', Config::getEditHtml() );
|
||||
Components::set(
|
||||
'group-defaultGroup-options',
|
||||
Forms::getOptionsHtml( self::$group->listGroupsSimple(), Config::getValue( 'group/defaultGroup' ) )
|
||||
);
|
||||
Views::view( 'admin.settings' );
|
||||
}
|
||||
}
|
88
app/controllers/admin/tokens.php
Executable file
88
app/controllers/admin/tokens.php
Executable file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* app/controllers/admin/tokens.php
|
||||
*
|
||||
* This is the admin app/user tokens 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\Admin;
|
||||
|
||||
use TheTempusProject\Classes\Forms as TTPForms;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Houdini\Classes\Issues;
|
||||
use TheTempusProject\Houdini\Classes\Navigation;
|
||||
use TheTempusProject\Houdini\Classes\Components;
|
||||
use TheTempusProject\Houdini\Classes\Forms;
|
||||
use TheTempusProject\Classes\AdminController;
|
||||
use TheTempusProject\Models\Token;
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\Bedrock\Functions\Check;
|
||||
use TheTempusProject\Hermes\Functions\Redirect;
|
||||
use TheTempusProject\Bedrock\Functions\Session;
|
||||
|
||||
class Tokens extends AdminController {
|
||||
public static $token;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$title = 'Admin - Tokens';
|
||||
self::$token = new Token;
|
||||
}
|
||||
|
||||
public function create() {
|
||||
if ( Input::exists( 'submit' ) ) {
|
||||
if ( !TTPForms::check( 'adminCreateToken' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your token.' => Check::userErrors() ] );
|
||||
}
|
||||
if ( self::$token->create(
|
||||
Input::post( 'name' ),
|
||||
Input::post( 'notes' ),
|
||||
Input::post( 'token_type' )
|
||||
) ) {
|
||||
Session::flash( 'success', 'Token Created' );
|
||||
Redirect::to( 'admin/tokens' );
|
||||
}
|
||||
}
|
||||
Views::view( 'admin.tokens.create' );
|
||||
}
|
||||
|
||||
public function delete( $id = null ) {
|
||||
if ( self::$token->delete( [ $id ] ) ) {
|
||||
Session::flash( 'success', 'Token deleted.' );
|
||||
}
|
||||
Redirect::to( 'admin/tokens' );
|
||||
}
|
||||
|
||||
public function edit( $id = null ) {
|
||||
$token = self::$token->findById( $id );
|
||||
if ( Input::exists( 'submit' ) ) {
|
||||
if ( !TTPForms::check( 'adminEditToken' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your token.' => Check::userErrors() ] );
|
||||
} else {
|
||||
if ( self::$token->update(
|
||||
$id,
|
||||
Input::post( 'name' ),
|
||||
Input::post( 'notes' ),
|
||||
Input::post( 'token_type' )
|
||||
) ) {
|
||||
Session::flash( 'success', 'Token Updated' );
|
||||
Redirect::to( 'admin/tokens' );
|
||||
}
|
||||
}
|
||||
}
|
||||
Forms::selectOption( $token->token_type );
|
||||
return Views::view( 'admin.tokens.edit', $token );
|
||||
}
|
||||
|
||||
public function index() {
|
||||
return Views::view( 'admin.tokens.list', self::$token->listPaginated() );
|
||||
}
|
||||
|
||||
public function view( $id = null ) {
|
||||
return Views::view( 'admin.tokens.view', self::$token->findById( $id ) );
|
||||
}
|
||||
}
|
209
app/controllers/admin/users.php
Executable file
209
app/controllers/admin/users.php
Executable file
@ -0,0 +1,209 @@
|
||||
<?php
|
||||
/**
|
||||
* app/controllers/admin/users.php
|
||||
*
|
||||
* This is the users admin 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\Admin;
|
||||
|
||||
use TheTempusProject\Bedrock\Functions\Check;
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\Bedrock\Functions\Code;
|
||||
use TheTempusProject\Bedrock\Functions\Hash;
|
||||
use TheTempusProject\Houdini\Classes\Navigation;
|
||||
use TheTempusProject\Houdini\Classes\Components;
|
||||
use TheTempusProject\Houdini\Classes\Forms;
|
||||
use TheTempusProject\Houdini\Classes\Issues;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Bedrock\Classes\Config;
|
||||
use TheTempusProject\Classes\Forms as FormChecker;
|
||||
use TheTempusProject\Classes\AdminController;
|
||||
use TheTempusProject\Models\User;
|
||||
use TheTempusProject\Models\Group;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
use TheTempusProject\Houdini\Classes\Template;
|
||||
use TheTempusProject\Bedrock\Functions\Upload;
|
||||
|
||||
class Users extends AdminController {
|
||||
public static $user;
|
||||
public static $group;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$title = 'Admin - Users';
|
||||
self::$user = new User;
|
||||
self::$group = new Group;
|
||||
}
|
||||
|
||||
public function create() {
|
||||
if ( Input::exists( 'submit' ) ) {
|
||||
if ( !FormChecker::check( 'createUser' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your request.' => Check::userErrors() ] );
|
||||
} else {
|
||||
$fields = [
|
||||
'username' => Input::post( 'username' ),
|
||||
'password' => Hash::make( Input::post( 'password' ) ),
|
||||
'email' => Input::post( 'email' ),
|
||||
'userGroup' => Input::post( 'groupSelect' ),
|
||||
'terms' => 0,
|
||||
];
|
||||
if ( !Input::exists( 'confirmation' ) ) {
|
||||
$fields['confirmed'] = 1;
|
||||
}
|
||||
if ( self::$user->create( $fields ) ) {
|
||||
Issues::add( 'success', 'User Created' );
|
||||
return $this->index();
|
||||
} else {
|
||||
Issues::add( 'error', 'There was an error creating the user' );
|
||||
}
|
||||
}
|
||||
}
|
||||
$select = Forms::getSelectHtml(
|
||||
'groupSelect',
|
||||
self::$group->listGroupsSimple(),
|
||||
Config::getValue( 'group/defaultGroup' ),
|
||||
);
|
||||
Components::set( 'groupSelect', $select );
|
||||
Views::view( 'admin.users.create' );
|
||||
}
|
||||
|
||||
public function delete( $id = null ) {
|
||||
if ( Input::exists( 'submit' ) ) {
|
||||
$id = Input::post( 'U_' );
|
||||
}
|
||||
if ( self::$user->delete( $id ) ) {
|
||||
Issues::add( 'success', 'User deleted' );
|
||||
} else {
|
||||
Issues::add( 'error', 'There was an error deleting user(s)' );
|
||||
}
|
||||
$this->index();
|
||||
}
|
||||
|
||||
public function edit( $id = null ) {
|
||||
if ( !Check::id( $id ) ) {
|
||||
return Issues::add( 'error', 'Invalid user' );
|
||||
}
|
||||
$userData = self::$user->findById( $id );
|
||||
if ( in_array( $userData->groupName, self::$group::$protectedGroups ) ) {
|
||||
switch ( $userData->groupName ) {
|
||||
case 'Super':
|
||||
if ( 'Super' !== App::$activeGroup->name ) {
|
||||
Issues::add( 'error', 'You do not have permission to do that.' );
|
||||
return $this->index();
|
||||
}
|
||||
case 'Admin':
|
||||
if ( 'Super' !== App::$activeGroup->name ) {
|
||||
Issues::add( 'error', 'You do not have permission to do that.' );
|
||||
return $this->index();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( Input::exists( 'submit' ) ) {
|
||||
if ( ! FormChecker::check( 'editUser' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your request.' => Check::userErrors() ] );
|
||||
} else {
|
||||
$fields = [
|
||||
'username' => Input::post( 'username' ),
|
||||
'email' => Input::post( 'email' ),
|
||||
'userGroup' => Input::post( 'groupSelect' ),
|
||||
];
|
||||
|
||||
if ( Input::exists( 'avatar' ) ) {
|
||||
$folder = UPLOAD_DIRECTORY . $userData->username . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR;
|
||||
$upload = Upload::image( 'avatar', $folder );
|
||||
if ( $upload ) {
|
||||
$route = str_replace( APP_ROOT_DIRECTORY, '', $folder );
|
||||
$prefs = [];
|
||||
$prefs['avatar'] = $route . Upload::last();
|
||||
|
||||
self::$user->updatePrefs( $prefs, $userData->ID );
|
||||
} else {
|
||||
Issues::add( 'error', [ 'There was an error with your avatar.' => Check::userErrors() ] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( Input::exists( 'password' ) ) {
|
||||
$fields['password'] = Hash::make( Input::post( 'password' ) );
|
||||
}
|
||||
|
||||
if ( Input::exists( 'confirmed' ) ) {
|
||||
$fields['confirmed'] = 1;
|
||||
} else {
|
||||
if ( Input::exists( 'confirmation' ) ) {
|
||||
$fields['confirmationCode'] = Code::genConfirmation();
|
||||
}
|
||||
}
|
||||
|
||||
if ( self::$user->update( $userData->ID, $fields ) ) {
|
||||
Issues::add( 'success', 'User Updated.' );
|
||||
return $this->index();
|
||||
} else {
|
||||
Issues::add( 'notice', 'There was an error with your request, please try again.' );
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( empty( $avatarLocation ) ) {
|
||||
$avatarLocation = $userData->prefs['avatar'];
|
||||
}
|
||||
if ( empty( $userGroup ) ) {
|
||||
$userGroup = $userData->userGroup;
|
||||
}
|
||||
Forms::selectRadio( 'confirmed', $userData->confirmed );
|
||||
|
||||
$avatar = $this->getAvatar( 'avatar', $avatarLocation );
|
||||
Components::set( 'AvatarSettings', $avatar );
|
||||
|
||||
$select = Forms::getSelectHtml(
|
||||
'groupSelect',
|
||||
self::$group->listGroupsSimple(),
|
||||
$userGroup,
|
||||
);
|
||||
Components::set( 'groupSelect', $select );
|
||||
Views::view( 'admin.users.edit', $userData );
|
||||
}
|
||||
|
||||
public function index() {
|
||||
Views::view( 'admin.users.list', self::$user->listPaginated() );
|
||||
}
|
||||
|
||||
public function view( $id = null ) {
|
||||
if ( !empty( $id ) ) {
|
||||
$userData = self::$user->findById( $id );
|
||||
if ( $userData !== false ) {
|
||||
return Views::view( 'admin.users.view', $userData );
|
||||
}
|
||||
Issues::add( 'error', 'User not found.' );
|
||||
}
|
||||
$this->index();
|
||||
}
|
||||
|
||||
private function getAvatar( $name, $value ) {
|
||||
$fieldname = str_ireplace( '/', '-', $name );
|
||||
|
||||
$html = '';
|
||||
$fieldHtml = '';
|
||||
$fieldHtml = Forms::getFileHtml( $fieldname );
|
||||
|
||||
$html .= '<div class="mb-3 row">';
|
||||
$html .= ' <label for="' . $fieldname . '" class="col-lg-6 col-form-label text-end">' . ucfirst( $fieldname ) . '</label>';
|
||||
$html .= ' <div class="col-lg-2">';
|
||||
$html .= ' ' . $fieldHtml;
|
||||
$html .= ' </div>';
|
||||
$html .= '</div>';
|
||||
|
||||
$html .= '<div class="mb-3 row">';
|
||||
$html .= ' <h4 class="col-lg-6 col-form-label text-end">Current Image</h4>';
|
||||
$html .= ' <div class="col-lg-2">';
|
||||
$html .= ' <img alt="User Avatar" src="{ROOT_URL}' . $value . '" class="img-circle img-fluid p-2 avatar-125">';
|
||||
$html .= ' </div>';
|
||||
$html .= '</div>';
|
||||
|
||||
return Template::parse( $html );
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user