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 );
|
||||
}
|
||||
}
|
40
app/controllers/api/auth.php
Executable file
40
app/controllers/api/auth.php
Executable file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* app/controllers/api/auth.php
|
||||
*
|
||||
* This is the api authentication 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\Api;
|
||||
|
||||
use TheTempusProject\Models\User;
|
||||
use TheTempusProject\Classes\ApiController;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Models\Token;
|
||||
|
||||
class Auth extends ApiController {
|
||||
public static $tokens;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$tokens = new Token;
|
||||
}
|
||||
|
||||
/**
|
||||
public function refresh() {
|
||||
$token = self::$tokens->refresh( self::$authToken->ID );
|
||||
if ( empty( $token ) ) {
|
||||
$responseType = 'error';
|
||||
$response = 'IRDK';
|
||||
} else {
|
||||
$responseType = 'token';
|
||||
$response = $token;
|
||||
}
|
||||
Views::view( 'api.response', ['response' => json_encode( [ $responseType => $response ], true )]);
|
||||
}
|
||||
*/
|
||||
}
|
52
app/controllers/api/login.php
Executable file
52
app/controllers/api/login.php
Executable file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* app/controllers/api/auth.php
|
||||
*
|
||||
* This is the api authentication 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\Api;
|
||||
|
||||
use TheTempusProject\Classes\ApiController;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Models\Token;
|
||||
use TheTempusProject\Models\User;
|
||||
use TheTempusProject\Houdini\Classes\Template;
|
||||
use TheTempusProject\Classes\Forms;
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
|
||||
class Login extends ApiController {
|
||||
public static $tokens;
|
||||
public static $user;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct( false );
|
||||
self::$tokens = new Token;
|
||||
self::$user = new User;
|
||||
Template::addHeader( 'Access-Control-Allow-Origin: *' );
|
||||
Template::addHeader( 'Content-Type: application/json; charset=utf-8' );
|
||||
}
|
||||
|
||||
/**
|
||||
public function index() {
|
||||
if ( ! Forms::check( 'apiLogin' ) ) {
|
||||
$responseType = 'error';
|
||||
$response = 'malformed input';
|
||||
return Views::view( 'api.response', ['response' => json_encode( [ $responseType => $response ], true )]);
|
||||
}
|
||||
$user = self::$user->authorize( Input::post( 'username' ), Input::post( 'password' ) );
|
||||
if ( ! $user ) {
|
||||
$responseType = 'error';
|
||||
$response = 'bad credentials';
|
||||
return Views::view( 'api.response', ['response' => json_encode( [ $responseType => $response ], true )]);
|
||||
}
|
||||
$responseType = 'token';
|
||||
$token = self::$tokens->findOrCreateUserToken( $user->ID, true );
|
||||
return Views::view( 'api.response', ['response' => json_encode( [ $responseType => $token ], true )]);
|
||||
}
|
||||
*/
|
||||
}
|
45
app/controllers/api/users.php
Executable file
45
app/controllers/api/users.php
Executable file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/**
|
||||
* app/controllers/api/users.php
|
||||
*
|
||||
* This is the users' api 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\Api;
|
||||
|
||||
use TheTempusProject\Models\User;
|
||||
use TheTempusProject\Classes\ApiController;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
|
||||
class Users extends ApiController {
|
||||
public static $user;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$user = new User;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is actually just for testing. It can provide attack information in the way of user count if not disabled.
|
||||
*
|
||||
* @param [type] $id
|
||||
* @return void
|
||||
*/
|
||||
/**
|
||||
public function find( $id = null ) {
|
||||
$user = self::$user->get( $id );
|
||||
if ( ! $user ) {
|
||||
$responseType = 'error';
|
||||
$response = 'No user found.';
|
||||
} else {
|
||||
$responseType = 'data';
|
||||
$response = $user->ID;
|
||||
}
|
||||
Views::view( 'api.response', ['response' => json_encode( [ $responseType => $response ], true )]);
|
||||
}
|
||||
*/
|
||||
}
|
27
app/controllers/error.php
Executable file
27
app/controllers/error.php
Executable file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* app/controllers/error.php
|
||||
*
|
||||
* This is the error 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\Houdini\Classes\Views;
|
||||
|
||||
class Error extends Controller {
|
||||
public function index() {
|
||||
self::$title = 'Error';
|
||||
self::$pageDescription = 'The application has encountered an error.';
|
||||
Views::view( 'errors.generic' );
|
||||
}
|
||||
|
||||
public function upload404() {
|
||||
Views::view( 'errors.upload404' );
|
||||
}
|
||||
}
|
115
app/controllers/home.php
Executable file
115
app/controllers/home.php
Executable file
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/**
|
||||
* app/controllers/home.php
|
||||
*
|
||||
* This is the home or 'index' 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\Hermes\Functions\Redirect;
|
||||
use TheTempusProject\Bedrock\Functions\Session;
|
||||
use TheTempusProject\Bedrock\Functions\Check;
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\Hermes\Functions\Route as Routes;
|
||||
use TheTempusProject\Houdini\Classes\Issues;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Houdini\Classes\Components;
|
||||
use TheTempusProject\Houdini\Classes\Template;
|
||||
use TheTempusProject\Classes\Controller;
|
||||
use TheTempusProject\Classes\Forms;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
|
||||
class Home extends Controller {
|
||||
public function index() {
|
||||
self::$title = '{SITENAME}';
|
||||
self::$pageDescription = '{SITENAME} is here to provide you a better, faster, and easier - way to create and manage your own web applications.';
|
||||
Views::view( 'index' );
|
||||
}
|
||||
|
||||
public function login() {
|
||||
self::$title = 'Portal - {SITENAME}';
|
||||
self::$pageDescription = 'Please log in to access all of the great features {SITENAME} has to offer.';
|
||||
if ( App::$isLoggedIn ) {
|
||||
return Issues::add( 'notice', 'You are already logged in. Please <a href="' . Routes::getAddress() . 'home/logout">click here</a> to log out.' );
|
||||
}
|
||||
if ( !Input::exists() ) {
|
||||
return Views::view( 'auth.login' );
|
||||
}
|
||||
if ( !Forms::check( 'login' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your login.' => Check::userErrors() ] );
|
||||
return Views::view( 'auth.login' );
|
||||
}
|
||||
if ( !self::$user->logIn( Input::post( 'username' ), Input::post( 'password' ), Input::post( 'remember' ) ) ) {
|
||||
Issues::add( 'error', 'Username or password was incorrect.' );
|
||||
return Views::view( 'auth.login' );
|
||||
}
|
||||
Session::flash( 'success', 'You have been logged in.' );
|
||||
if ( Input::exists( 'rurl' ) ) {
|
||||
Redirect::to( Input::post( 'rurl' ) );
|
||||
} else {
|
||||
Redirect::to( 'home/index' );
|
||||
}
|
||||
}
|
||||
|
||||
public function logout() {
|
||||
self::$title = 'Log Out - {SITENAME}';
|
||||
Template::noIndex();
|
||||
if ( !App::$isLoggedIn ) {
|
||||
return Issues::add( 'notice', 'You are not logged in.' );
|
||||
}
|
||||
self::$user->logOut();
|
||||
Session::flash( 'success', 'You have been logged out.' );
|
||||
Redirect::to( 'home/index' );
|
||||
}
|
||||
|
||||
public function profile( $id = null ) {
|
||||
self::$title = 'User Profile - {SITENAME}';
|
||||
self::$pageDescription = 'User Profile - {SITENAME}';
|
||||
if ( !App::$isLoggedIn ) {
|
||||
return Issues::add( 'notice', 'You must be logged in to view this page.' );
|
||||
}
|
||||
$user = self::$user->get( $id );
|
||||
if ( !$user ) {
|
||||
return Issues::add( 'notice', 'No user found.' );
|
||||
}
|
||||
self::$title = $user->username . '\'s Profile - {SITENAME}';
|
||||
self::$pageDescription = 'User Profile for ' . $user->username . ' - {SITENAME}';
|
||||
Views::view( 'profilePage', $user );
|
||||
}
|
||||
|
||||
public function terms() {
|
||||
self::$title = 'Terms and Conditions - {SITENAME}';
|
||||
self::$pageDescription = '{SITENAME} Terms and Conditions of use. Please use {SITENAME} safely.';
|
||||
Components::set( 'TERMS', Views::simpleView( 'auth.terms' ) );
|
||||
Views::view( 'termsPage' );
|
||||
}
|
||||
|
||||
public function about() {
|
||||
self::$title = 'About - {SITENAME}';
|
||||
self::$pageDescription = '{SITENAME} was started by a developer with years of industry experience which has lead to a refined no-nonsense tool for everyone. Find out more about us here.';
|
||||
Views::view( 'about' );
|
||||
}
|
||||
|
||||
public function privacy() {
|
||||
self::$title = 'Privacy Policy - {SITENAME}';
|
||||
self::$pageDescription = 'At {SITENAME} you privacy is very important to us. On this page you can find a detailed outline of all the information we collect and how its used.';
|
||||
Views::view( 'privacy' );
|
||||
}
|
||||
|
||||
public function faq() {
|
||||
self::$title = 'Frequently Asked Questions - {SITENAME}';
|
||||
self::$pageDescription = 'Many times, we aren\'t the first to ask why or how something works. Here you will find a list of {SITENAME} commonly asked questions and our best answers.' ;
|
||||
Views::view( 'faq' );
|
||||
}
|
||||
|
||||
public function getstarted() {
|
||||
self::$title = 'Get Started - {SITENAME}';
|
||||
self::$pageDescription = '{SITENAME} is a great tool to bring your ideas to reality. On this page, you can find out how to get started today.' ;
|
||||
Views::view( 'start' );
|
||||
}
|
||||
}
|
125
app/controllers/libraries.php
Normal file
125
app/controllers/libraries.php
Normal file
@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* app/controllers/houdini.php
|
||||
*
|
||||
* This is the houdini 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\Hermes\Functions\Redirect;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Classes\Controller;
|
||||
|
||||
class Libraries extends Controller {
|
||||
public function index() {
|
||||
self::$title = 'Libraries - {SITENAME}';
|
||||
self::$pageDescription = '{SITENAME} depends on several very important libraries, some of which are developed exclusively to support the project. Here you can find a list with more information.' ;
|
||||
Views::view( 'deps.index' );
|
||||
}
|
||||
|
||||
public function ttp( $method = null ) {
|
||||
self::$title = '{SITENAME} - TheTempusProject';
|
||||
self::$pageDescription = 'TheTempusProject is the primary repo of {SITENAME} which houses the main application.';
|
||||
if ( empty( $method ) ) {
|
||||
return Views::view( 'deps.ttp' );
|
||||
}
|
||||
switch ( $method ) {
|
||||
case 'git':
|
||||
return Redirect::external( 'https://git.thetempusproject.com/the-tempus-project/thetempusproject' );
|
||||
case 'packagist':
|
||||
return Redirect::external( 'https://packagist.org/packages/thetempusproject/thetempusproject' );
|
||||
case 'changes':
|
||||
self::$title .= ' Changes';
|
||||
self::$pageDescription = 'This pages lists the most recent changes to TheTempusProject with some details on those changes.';
|
||||
return Views::view( 'changes.ttp' );
|
||||
default:
|
||||
return Views::view( 'deps.ttp' );
|
||||
}
|
||||
}
|
||||
|
||||
public function hermes( $method = null ) {
|
||||
self::$title = '{SITENAME} - Hermes';
|
||||
self::$pageDescription = 'Hermes is a dependency of {SITENAME} that provides many common helper functions for navigating url components and file systems; designed to work seamlessly regardless of architecture.';
|
||||
if ( empty( $method ) ) {
|
||||
return Views::view( 'deps.hermes' );
|
||||
}
|
||||
switch ( $method ) {
|
||||
case 'git':
|
||||
return Redirect::external( 'https://git.thetempusproject.com/the-tempus-project/hermes' );
|
||||
case 'packagist':
|
||||
return Redirect::external( 'https://packagist.org/packages/thetempusproject/hermes' );
|
||||
case 'changes':
|
||||
self::$title .= ' Changes';
|
||||
self::$pageDescription = 'Hermes is a dependency of {SITENAME} and this pages lists the most recent changes with some details on those changes.';
|
||||
return Views::view( 'changes.hermes' );
|
||||
default:
|
||||
return Views::view( 'deps.hermes' );
|
||||
}
|
||||
}
|
||||
|
||||
public function canary( $method = null ) {
|
||||
self::$title = '{SITENAME} - Canary';
|
||||
self::$pageDescription = 'Canary is a dependency of {SITENAME} that both records and reports logs from various PHP applications.';
|
||||
if ( empty( $method ) ) {
|
||||
return Views::view( 'deps.canary' );
|
||||
}
|
||||
switch ( $method ) {
|
||||
case 'git':
|
||||
return Redirect::external( 'https://git.thetempusproject.com/the-tempus-project/canary' );
|
||||
case 'packagist':
|
||||
return Redirect::external( 'https://packagist.org/packages/thetempusproject/canary' );
|
||||
case 'changes':
|
||||
self::$title .= ' Changes';
|
||||
self::$pageDescription = 'Canary is a dependency of {SITENAME} and this pages lists the most recent changes with some details on those changes.';
|
||||
return Views::view( 'changes.canary' );
|
||||
default:
|
||||
return Views::view( 'deps.canary' );
|
||||
}
|
||||
}
|
||||
|
||||
public function bedrock( $method = null ) {
|
||||
self::$title = '{SITENAME} - Bedrock';
|
||||
self::$pageDescription = 'Bedrock is a dependency of {SITENAME} that provides many components used to manipulate database data and many helper functions vital for running the entire application.';
|
||||
if ( empty( $method ) ) {
|
||||
return Views::view( 'deps.bedrock' );
|
||||
}
|
||||
switch ( $method ) {
|
||||
case 'git':
|
||||
return Redirect::external( 'https://git.thetempusproject.com/the-tempus-project/bedrock' );
|
||||
case 'packagist':
|
||||
return Redirect::external( 'https://packagist.org/packages/thetempusproject/bedrock' );
|
||||
case 'changes':
|
||||
self::$title .= ' Changes';
|
||||
self::$pageDescription = 'Bedrock is a dependency of {SITENAME} and this pages lists the most recent changes with some details on those changes.';
|
||||
return Views::view( 'changes.bedrock' );
|
||||
default:
|
||||
return Views::view( 'deps.bedrock' );
|
||||
}
|
||||
}
|
||||
|
||||
public function houdini( $method = null ) {
|
||||
self::$title = '{SITENAME} - Houdini';
|
||||
self::$pageDescription = 'Houdini is a dependency of {SITENAME} that allows for the creation and manipulation of objects used in html page creation.';
|
||||
if ( empty( $method ) ) {
|
||||
return Views::view( 'deps.houdini' );
|
||||
}
|
||||
switch ( $method ) {
|
||||
case 'git':
|
||||
return Redirect::external( 'https://git.thetempusproject.com/the-tempus-project/houdini' );
|
||||
case 'packagist':
|
||||
return Redirect::external( 'https://packagist.org/packages/thetempusproject/houdini' );
|
||||
case 'changes':
|
||||
self::$title .= ' Changes';
|
||||
self::$pageDescription = 'Houdini is a dependency of {SITENAME} and this pages lists the most recent changes with some details on those changes.';
|
||||
return Views::view( 'changes.houdini' );
|
||||
default:
|
||||
return Views::view( 'deps.houdini' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
148
app/controllers/register.php
Executable file
148
app/controllers/register.php
Executable file
@ -0,0 +1,148 @@
|
||||
<?php
|
||||
/**
|
||||
* app/controllers/register.php
|
||||
*
|
||||
* This is the user registration controller.
|
||||
*
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Controllers;
|
||||
|
||||
use TheTempusProject\Houdini\Classes\Template;
|
||||
use TheTempusProject\Classes\Email;
|
||||
use TheTempusProject\Bedrock\Functions\Check;
|
||||
use TheTempusProject\Bedrock\Functions\Session;
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\Bedrock\Functions\Hash;
|
||||
use TheTempusProject\Hermes\Functions\Redirect;
|
||||
use TheTempusProject\Houdini\Classes\Issues;
|
||||
use TheTempusProject\Houdini\Classes\Components;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
use TheTempusProject\Classes\Controller;
|
||||
use TheTempusProject\Classes\Forms;
|
||||
use TheTempusProject\Bedrock\Classes\Config;
|
||||
|
||||
class Register extends Controller {
|
||||
public function confirm( $code = null ) {
|
||||
Template::noIndex();
|
||||
self::$title = 'Confirm Email';
|
||||
if ( !isset( $code ) && !Input::exists( 'confirmationCode' ) ) {
|
||||
return Views::view( 'auth.confirmation' );
|
||||
}
|
||||
if ( Forms::check( 'emailConfirmation' ) ) {
|
||||
$code = Input::post( 'confirmationCode' );
|
||||
}
|
||||
if ( !self::$user->confirm( $code ) ) {
|
||||
Issues::add( 'error', 'There was an error confirming your account, please try again.' );
|
||||
return Views::view( 'auth.confirmation' );
|
||||
}
|
||||
Session::flash( 'success', 'You have successfully confirmed your email address.' );
|
||||
Redirect::to( 'home/index' );
|
||||
}
|
||||
|
||||
public function index() {
|
||||
self::$title = '{SITENAME} Sign Up';
|
||||
self::$pageDescription = 'Many features of {SITENAME} are disabled or hidden from unregistered users. On this page you can sign up for an account to access all the app has to offer.';
|
||||
|
||||
if ( ! Config::getValue( 'main/registrationEnabled' ) ) {
|
||||
return Issues::add( 'notice', 'The site administrator has disable the ability to register a new account.' );
|
||||
}
|
||||
|
||||
Components::set( 'TERMS', Views::simpleView( 'auth.terms' ) );
|
||||
if ( App::$isLoggedIn ) {
|
||||
return Issues::add( 'notice', 'You are currently logged in.' );
|
||||
}
|
||||
if ( !Input::exists() ) {
|
||||
return Views::view( 'auth.register' );
|
||||
}
|
||||
if ( !Forms::check( 'register' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your registration.' => Check::userErrors() ] );
|
||||
return Views::view( 'auth.register' );
|
||||
}
|
||||
self::$user->create( [
|
||||
'username' => Input::post( 'username' ),
|
||||
'password' => Hash::make( Input::post( 'password' ) ),
|
||||
'email' => Input::post( 'email' ),
|
||||
'terms' => 1,
|
||||
] );
|
||||
Session::flash( 'success', 'Thank you for registering! Please check your email to confirm your account.' );
|
||||
Redirect::to( 'home/index' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Come back and separate this into multiple forms because this is gross.
|
||||
*/
|
||||
public function recover() {
|
||||
self::$title = 'Recover Account - {SITENAME}';
|
||||
Template::noIndex();
|
||||
if ( !Input::exists() ) {
|
||||
return Views::view( 'auth.forgot' );
|
||||
}
|
||||
if ( Check::email( Input::post( 'entry' ) ) && self::$user->findByEmail( Input::post( 'entry' ) ) ) {
|
||||
$userData = self::$user->data();
|
||||
Email::send( $userData->email, 'forgotUsername', $userData->username, [ 'template' => true ] );
|
||||
Session::flash( 'notice', 'Your Username has been sent to your registered email address.' );
|
||||
Redirect::to( 'home/login' );
|
||||
} elseif ( self::$user->get( Input::post( 'entry' ) ) ) {
|
||||
self::$user->newCode( self::$user->data()->ID );
|
||||
self::$user->get( Input::post( 'entry' ) );
|
||||
$userData = self::$user->data();
|
||||
Email::send( $userData->email, 'forgotPassword', $userData->confirmationCode, [ 'template' => true ] );
|
||||
Session::flash( 'notice', 'Details for resetting your password have been sent to your registered email address' );
|
||||
Redirect::to( 'home/login' );
|
||||
}
|
||||
Issues::add( 'error', 'User not found.' );
|
||||
Views::view( 'auth.forgot' );
|
||||
}
|
||||
|
||||
public function resend() {
|
||||
self::$title = 'Resend Confirmation';
|
||||
Template::noIndex();
|
||||
if ( !App::$isLoggedIn ) {
|
||||
return Issues::add( 'notice', 'Please log in to resend your confirmation email.' );
|
||||
}
|
||||
if ( App::$activeUser->confirmed == '1' ) {
|
||||
return Issues::add( 'notice', 'Your account has already been confirmed.' );
|
||||
}
|
||||
if ( !Forms::check( 'confirmationResend' ) ) {
|
||||
return Views::view( 'auth.confirmation_resend' );
|
||||
}
|
||||
Email::send( App::$activeUser->email, 'confirmation', App::$activeUser->confirmationCode, [ 'template' => true ] );
|
||||
Session::flash( 'success', 'Your confirmation email has been sent to the email for your account.' );
|
||||
Redirect::to( 'home/index' );
|
||||
}
|
||||
|
||||
public function reset( $code = null ) {
|
||||
self::$title = 'Password Reset';
|
||||
Template::noIndex();
|
||||
if ( !isset( $code ) && !Input::exists( 'resetCode' ) ) {
|
||||
Issues::add( 'info', 'Please provide a reset code.' );
|
||||
return Views::view( 'auth.password_reset_code' );
|
||||
}
|
||||
if ( Input::exists( 'resetCode' ) ) {
|
||||
if ( Forms::check( 'passwordResetCode' ) ) {
|
||||
$code = Input::post( 'resetCode' );
|
||||
}
|
||||
}
|
||||
if ( ! self::$user->checkCode( $code ) ) {
|
||||
Issues::add( 'error', 'There was an error with your reset code. Please try again.' );
|
||||
return Views::view( 'auth.password_reset_code' );
|
||||
}
|
||||
Components::set( 'resetCode', $code );
|
||||
if ( ! Input::exists('password') ) {
|
||||
return Views::view( 'auth.password_reset' );
|
||||
}
|
||||
if ( ! Forms::check( 'passwordReset' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your request.' => Check::userErrors() ] );
|
||||
return Views::view( 'auth.password_reset' );
|
||||
}
|
||||
self::$user->changePassword( $code, Input::post( 'password' ) );
|
||||
Email::send( self::$user->data()->email, 'passwordChange', null, [ 'template' => true ] );
|
||||
Session::flash( 'success', 'Your Password has been changed, please use your new password to log in.' );
|
||||
Redirect::to( 'home/login' );
|
||||
}
|
||||
}
|
157
app/controllers/usercp.php
Executable file
157
app/controllers/usercp.php
Executable file
@ -0,0 +1,157 @@
|
||||
<?php
|
||||
/**
|
||||
* app/controllers/usercp.php
|
||||
*
|
||||
* This is the user control panel controller.
|
||||
*
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Controllers;
|
||||
|
||||
use TheTempusProject\Houdini\Classes\Template;
|
||||
use TheTempusProject\Classes\Email;
|
||||
use TheTempusProject\Bedrock\Functions\Code;
|
||||
use TheTempusProject\Bedrock\Functions\Check;
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\Bedrock\Functions\Hash;
|
||||
use TheTempusProject\Houdini\Classes\Components;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Houdini\Classes\Issues;
|
||||
use TheTempusProject\Houdini\Classes\Navigation;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
use TheTempusProject\Classes\Controller;
|
||||
use TheTempusProject\Classes\Preferences;
|
||||
use TheTempusProject\Classes\Forms;
|
||||
use TheTempusProject\Hermes\Functions\Redirect;
|
||||
use TheTempusProject\Bedrock\Functions\Session;
|
||||
|
||||
class Usercp extends Controller {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
if ( !App::$isLoggedIn ) {
|
||||
Session::flash( 'notice', 'You must be logged in to view this page!' );
|
||||
Redirect::home();
|
||||
}
|
||||
Template::noIndex();
|
||||
}
|
||||
|
||||
public function email() {
|
||||
self::$title = 'Email Settings';
|
||||
$menu = Views::simpleView( 'nav.usercp', App::$userCPlinks );
|
||||
Navigation::activePageSelect( $menu, null, true, true );
|
||||
if ( App::$activeUser->confirmed != '1' ) {
|
||||
return Issues::add( 'notice', 'You need to confirm your email address before you can make modifications. If you would like to resend that confirmation link, please <a href="/register/resend">click here</a>', true );
|
||||
}
|
||||
if ( !Input::exists() ) {
|
||||
return Views::view( 'user_cp.email_change' );
|
||||
}
|
||||
if ( !Forms::check( 'changeEmail' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your request.' => Check::userErrors() ] );
|
||||
return Views::view( 'user_cp.email_change' );
|
||||
}
|
||||
$code = Code::genConfirmation();
|
||||
self::$user->update(
|
||||
App::$activeUser->ID,
|
||||
[
|
||||
'confirmed' => 0,
|
||||
'email' => Input::post( 'email' ),
|
||||
'confirmationCode' => $code,
|
||||
],
|
||||
);
|
||||
Email::send( App::$activeUser->email, 'emailChangeNotice', $code, [ 'template' => true ] );
|
||||
Email::send( Input::post( 'email' ), 'emailChange', $code, [ 'template' => true ] );
|
||||
Issues::add( 'notice', 'Email has been changed, please check your email to confirm it.' );
|
||||
}
|
||||
|
||||
public function index() {
|
||||
self::$title = 'User Control Panel';
|
||||
$menu = Views::simpleView( 'nav.usercp', App::$userCPlinks );
|
||||
Navigation::activePageSelect( $menu, null, true, true );
|
||||
Views::view( 'user_cp.profile', App::$activeUser );
|
||||
}
|
||||
|
||||
public function password() {
|
||||
self::$title = 'Password Settings';
|
||||
$menu = Views::simpleView( 'nav.usercp', App::$userCPlinks );
|
||||
Navigation::activePageSelect( $menu, null, true, true );
|
||||
if ( !Input::exists() ) {
|
||||
return Views::view( 'user_cp.password_change' );
|
||||
}
|
||||
if ( !Hash::check( Input::post( 'curpass' ), App::$activeUser->password ) ) {
|
||||
Issues::add( 'error', 'Current password was incorrect.' );
|
||||
return Views::view( 'user_cp.password_change' );
|
||||
}
|
||||
if ( !Forms::check( 'changePassword' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your request.' => Check::userErrors() ] );
|
||||
return Views::view( 'user_cp.password_change' );
|
||||
}
|
||||
self::$user->update(
|
||||
App::$activeUser->ID,
|
||||
[ 'password' => Hash::make( Input::post( 'password' ) ) ],
|
||||
);
|
||||
Email::send( App::$activeUser->email, 'passwordChange', null, [ 'template' => true ] );
|
||||
Issues::add( 'notice', 'Your Password has been changed!' );
|
||||
}
|
||||
|
||||
public function settings() {
|
||||
self::$title = 'Preferences';
|
||||
$menu = Views::simpleView( 'nav.usercp', App::$userCPlinks );
|
||||
Navigation::activePageSelect( $menu, null, true, true );
|
||||
$prefs = new Preferences;
|
||||
$userPrefs = App::$activePrefs;
|
||||
if ( Input::exists( 'submit' ) ) {
|
||||
$fields = $prefs->convertFormToArray( true, false );
|
||||
// @TODO now i may need to rework the form checker to work with this....
|
||||
// if (!Forms::check('userPrefs')) {
|
||||
// Issues::add( 'error', [ 'There was an error with your request.' => Check::userErrors() ] );
|
||||
// }
|
||||
self::$user->updatePrefs( $fields, App::$activeUser->ID );
|
||||
Issues::add( 'success', 'Your preferences have been updated.' );
|
||||
// if the image upload fails, need to fall back on original
|
||||
if ( empty( $fields['avatar'] ) ) {
|
||||
$fields['avatar'] = $userPrefs['avatar'];
|
||||
}
|
||||
} else {
|
||||
$fields = $userPrefs;
|
||||
}
|
||||
Components::set( 'AVATAR_SETTINGS', $fields['avatar'] );
|
||||
Components::set( 'PREFERENCES_FORM', $prefs->getFormHtml( $fields ) );
|
||||
Views::view( 'user_cp.settings', App::$activeUser );
|
||||
}
|
||||
|
||||
public function updatePref() {
|
||||
Template::setTemplate( 'api' );
|
||||
if ( ! App::$isLoggedIn ) {
|
||||
return Views::view( 'api.response', ['response' => json_encode( [ 'error' => 'Not Logged In' ], true )]);
|
||||
}
|
||||
if ( ! Forms::check( 'updatePreference' ) ) {
|
||||
return Views::view( 'api.response', ['response' => json_encode( [ 'error' => Check::userErrors() ], true )]);
|
||||
}
|
||||
$name = Input::post( 'prefName' );
|
||||
$value = Input::post('prefValue' );
|
||||
|
||||
if ( 'false' === $value ) {
|
||||
$value = false;
|
||||
} elseif ( 'true' === $value ) {
|
||||
$value = true;
|
||||
}
|
||||
|
||||
if ( empty( Preferences::get( $name ) ) ) {
|
||||
return Views::view( 'api.response', ['response' => json_encode( [ 'error' => 'Unknown Preference' ], true )]);
|
||||
}
|
||||
|
||||
$prefs = new Preferences;
|
||||
$fields1 = $prefs->convertFormToArray( true, false );
|
||||
$fields3 = $fields1;
|
||||
|
||||
if ( isset( $fields1[ $name ] ) ) {
|
||||
$fields3[ $name ] = $value;
|
||||
}
|
||||
$result = self::$user->updatePrefs( $fields3, App::$activeUser->ID );
|
||||
|
||||
return Views::view( 'api.response', ['response' => json_encode( $result, true )]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user