many fixes and updates
This commit is contained in:
@ -22,25 +22,31 @@ use TheTempusProject\Classes\Controller;
|
||||
use TheTempusProject\Classes\Forms;
|
||||
use TheTempusProject\Models\Bookmarks as Bookmark;
|
||||
use TheTempusProject\Models\Folders;
|
||||
use TheTempusProject\Models\BookmarkDashboards as Dashboards;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
use TheTempusProject\Houdini\Classes\Components;
|
||||
use TheTempusProject\Houdini\Classes\Forms as HoudiniForms;
|
||||
use TheTempusProject\Houdini\Classes\Navigation;
|
||||
use TheTempusProject\Houdini\Classes\Template;
|
||||
use TheTempusProject\Hermes\Functions\Route as Routes;
|
||||
use TheTempusProject\Models\User;
|
||||
use TheTempusProject\Classes\Preferences;
|
||||
use TheTempusProject\Canary\Bin\Canary as Debug;
|
||||
|
||||
class Bookmarks extends Controller {
|
||||
protected static $bookmarks;
|
||||
protected static $folders;
|
||||
protected static $dashboards;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
if ( !App::$isLoggedIn ) {
|
||||
if ( ! App::$isLoggedIn ) {
|
||||
Session::flash( 'notice', 'You must be logged in to create or manage bookmarks.' );
|
||||
return Redirect::home();
|
||||
}
|
||||
self::$bookmarks = new Bookmark;
|
||||
self::$folders = new Folders;
|
||||
self::$dashboards = new Dashboards;
|
||||
self::$title = 'Bookmarks - {SITENAME}';
|
||||
self::$pageDescription = 'Add and save url bookmarks here.';
|
||||
|
||||
@ -57,14 +63,23 @@ class Bookmarks extends Controller {
|
||||
Components::set( 'SITE_URL', Routes::getAddress() );
|
||||
Views::raw( $tabsView );
|
||||
Components::append( 'TEMPLATE_JS_INCLUDES', Template::parse('<script language="JavaScript" crossorigin="anonymous" type="text/javascript" src="{ROOT_URL}app/plugins/bookmarks/js/bookmarks.js"></script>' ) );
|
||||
$options = Views::simpleView( 'bookmarks.nav.viewOptions' );
|
||||
Components::set( 'VIEW_OPTIONS', $options );
|
||||
$viewOptions = Views::simpleView( 'bookmarks.nav.viewOptions' );
|
||||
Components::set( 'VIEW_OPTIONS', $viewOptions );
|
||||
$dashOptions = Views::simpleView( 'bookmarks.dashboards.dashOptions' );
|
||||
Components::set( 'DASH_OPTIONS', $dashOptions );
|
||||
$this->setPrefToggles();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$bookmarks = self::$bookmarks->noFolder();
|
||||
if ( Input::exists('submit') ) {
|
||||
$prefs = new Preferences;
|
||||
$user = new User;
|
||||
$fields = $prefs->convertFormToArray( true );
|
||||
$out = $user->updatePrefs( $fields, App::$activeUser->ID );
|
||||
$this->setPrefToggles();
|
||||
}
|
||||
|
||||
$folders = self::$folders->byUser();
|
||||
|
||||
$panelArray = [];
|
||||
if ( !empty( $folders ) ) {
|
||||
foreach ( $folders as $folder ) {
|
||||
@ -79,9 +94,7 @@ class Bookmarks extends Controller {
|
||||
$panelArray[] = $folderObject;
|
||||
}
|
||||
}
|
||||
Components::set( 'foldersList', Views::simpleView( 'bookmarks.folders.list', $folders ) );
|
||||
Components::set( 'folderPanels', Views::simpleView( 'bookmarks.components.bookmarkListPanel', $panelArray ) );
|
||||
Components::set( 'bookmarksList', Views::simpleView( 'bookmarks.bookmarks.list', $bookmarks ) );
|
||||
return Views::view( 'bookmarks.dash' );
|
||||
}
|
||||
|
||||
@ -102,6 +115,11 @@ class Bookmarks extends Controller {
|
||||
return Views::view( 'bookmarks.bookmarks.view', $bookmark );
|
||||
}
|
||||
|
||||
public function unsorted() {
|
||||
$bookmarks = self::$bookmarks->noFolder();
|
||||
Views::view( 'bookmarks.bookmarks.unsorted', $bookmarks );
|
||||
}
|
||||
|
||||
public function bookmarks( $id = null ) {
|
||||
$folder = self::$folders->findById( $id );
|
||||
if ( $folder == false ) {
|
||||
@ -113,8 +131,6 @@ class Bookmarks extends Controller {
|
||||
return Redirect::to( 'bookmarks/index' );
|
||||
}
|
||||
Navigation::setCrumbComponent( 'BookmarkBreadCrumbs', 'bookmarks/bookmarks/' . $id );
|
||||
|
||||
$bookmarks = self::$bookmarks->noFolder();
|
||||
|
||||
$panelArray = [];
|
||||
$panel = new \stdClass();
|
||||
@ -325,6 +341,179 @@ class Bookmarks extends Controller {
|
||||
Redirect::to( 'bookmarks/folders' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Dashboards
|
||||
*/
|
||||
public function addDash() {
|
||||
$folders = self::$folders->byUser() ?? [];
|
||||
|
||||
if ( !empty( $folders ) ) {
|
||||
foreach ( $folders as &$folder ) {
|
||||
$folder->selected = '';
|
||||
}
|
||||
}
|
||||
|
||||
$linkSelect = Views::simpleView( 'bookmarks.components.linkSelect', $folders );
|
||||
Components::set( 'LINK_SELECT', $linkSelect );
|
||||
|
||||
if ( ! Input::exists( 'submit' ) ) {
|
||||
return Views::view( 'bookmarks.dashboards.create' );
|
||||
}
|
||||
|
||||
if ( !Forms::check( 'createDashboard' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error creating your dashboard.' => Check::userErrors() ] );
|
||||
return Views::view( 'bookmarks.dashboards.create' );
|
||||
}
|
||||
|
||||
if ( is_array( Input::post('link_filter') ) && ! empty( Input::post('link_filter') ) ) {
|
||||
$filters = implode( ',', Input::post('link_filter') );
|
||||
} else {
|
||||
$filters = '';
|
||||
}
|
||||
if ( is_array( Input::post('link_order') ) && ! empty( Input::post('link_order') ) ) {
|
||||
$folders = implode( ',', Input::post('link_order') );
|
||||
} else {
|
||||
$folders = '';
|
||||
}
|
||||
$result = self::$dashboards->create( Input::post('title'), $filters, $folders, Input::post('description') );
|
||||
|
||||
if ( !$result ) {
|
||||
Issues::add( 'error', [ 'There was an error creating your dashboard.' => Check::userErrors() ] );
|
||||
return Views::view( 'bookmarks.dashboards.create' );
|
||||
}
|
||||
|
||||
Issues::add( 'success', 'Your dashboard has been created.' );
|
||||
return $this->dashboards();
|
||||
}
|
||||
|
||||
public function editDash( $id = null ) {
|
||||
$dash = self::$dashboards->findById( $id );
|
||||
|
||||
if ( $dash == false ) {
|
||||
Issues::add( 'error', 'Unknown Dashboard' );
|
||||
return $this->dashboards();
|
||||
}
|
||||
|
||||
if ( $dash->createdBy != App::$activeUser->ID ) {
|
||||
Issues::add( 'error', 'You do not have permission to view this dashboard.' );
|
||||
return $this->dashboards();
|
||||
}
|
||||
|
||||
$this->setDashToggles( explode( ',', $dash->saved_prefs ) );
|
||||
|
||||
$folders = self::$folders->byUser() ?? [];
|
||||
$selectedFolders = explode( ',', $dash->link_order );
|
||||
if ( !empty( $folders ) ) {
|
||||
foreach ( $folders as &$folder ) {
|
||||
if ( in_array( $folder->ID, $selectedFolders ) ) {
|
||||
$folder->selected = ' checked';
|
||||
} else {
|
||||
$folder->selected = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$linkSelect = Views::simpleView( 'bookmarks.components.linkSelect', $folders );
|
||||
Components::set( 'LINK_SELECT', $linkSelect );
|
||||
|
||||
if ( ! Input::exists( 'submit' ) ) {
|
||||
return Views::view( 'bookmarks.dashboards.edit', $dash );
|
||||
}
|
||||
|
||||
if ( ! Forms::check( 'editDashboard' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error editing your dashboard.' => Check::userErrors() ] );
|
||||
return Views::view( 'bookmarks.dashboards.edit', $dash );
|
||||
}
|
||||
|
||||
if ( is_array( Input::post('link_filter') ) && ! empty( Input::post('link_filter') ) ) {
|
||||
$filters = implode( ',', Input::post('link_filter') );
|
||||
} else {
|
||||
$filters = '';
|
||||
}
|
||||
|
||||
if ( is_array( Input::post('link_order') ) && ! empty( Input::post('link_order') ) ) {
|
||||
$folders = implode( ',', Input::post('link_order') );
|
||||
} else {
|
||||
$folders = '';
|
||||
}
|
||||
|
||||
$result = self::$dashboards->update( $id, Input::post('title'), $filters, $folders, Input::post('description') );
|
||||
|
||||
if ( !$result ) {
|
||||
Issues::add( 'error', [ 'There was an error updating your dashboard.' => Check::userErrors() ] );
|
||||
return Views::view( 'bookmarks.dashboards.edit', $dash );
|
||||
}
|
||||
|
||||
Issues::add( 'success', 'Your dashboard has been updated.' );
|
||||
return $this->dashboards();
|
||||
}
|
||||
|
||||
public function deleteDash( $id = null ) {
|
||||
$dash = self::$dashboards->findById( $id );
|
||||
if ( $dash == false ) {
|
||||
Issues::add( 'error', 'Unknown Dashboard' );
|
||||
return $this->dashboards();
|
||||
}
|
||||
if ( $dash->createdBy != App::$activeUser->ID ) {
|
||||
Issues::add( 'error', 'You do not have permission to delete this dash.' );
|
||||
return $this->dashboards();
|
||||
}
|
||||
$result = self::$dashboards->delete( $id );
|
||||
if ( !$result ) {
|
||||
Issues::add( 'error', 'There was an error deleting the dashboard(s)' );
|
||||
} else {
|
||||
Issues::add( 'success', 'Dashboard deleted' );
|
||||
}
|
||||
return $this->dashboards();
|
||||
}
|
||||
|
||||
public function dashboard( $uuid = null ) {
|
||||
$dash = self::$dashboards->findByUuid( $uuid );
|
||||
if ( $dash == false ) {
|
||||
return $this->dashboards();
|
||||
}
|
||||
if ( $dash->createdBy != App::$activeUser->ID ) {
|
||||
Issues::add( 'error', 'You do not have permission to view this dash.' );
|
||||
return $this->dashboards();
|
||||
}
|
||||
|
||||
$foldersArray = [];
|
||||
if ( ! empty( $dash->link_order ) ) {
|
||||
$folders = explode( ',', $dash->link_order );
|
||||
foreach ( $folders as $key => $id ) {
|
||||
$folder = self::$folders->findById( $id );
|
||||
if ( empty( $folder ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$bookmarks = self::$bookmarks->byFolder( $folder->ID );
|
||||
if ( empty( $bookmarks ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$folderObject = new \stdClass();
|
||||
$folderObject->ID = $folder->ID;
|
||||
$folderObject->title = $folder->title;
|
||||
$folderObject->color = $folder->color;
|
||||
$folderObject->uuid = $folder->uuid;
|
||||
$folderObject->bookmarkRows = Views::simpleView( 'bookmarks.dashboards.bookmarkRows', $bookmarks );
|
||||
$foldersArray[] = $folderObject;
|
||||
}
|
||||
}
|
||||
Components::set( 'folderPanels', Views::simpleView( 'bookmarks.dashboards.folderPanels', $foldersArray ) );
|
||||
|
||||
if ( ! empty( $dash->saved_prefs ) ) {
|
||||
$this->setDashToggles( explode( ',', $dash->saved_prefs ) );
|
||||
}
|
||||
|
||||
return Views::view( 'bookmarks.dashboards.view', $dash );
|
||||
}
|
||||
|
||||
public function dashboards() {
|
||||
$dashboards = self::$dashboards->byUser();
|
||||
return Views::view( 'bookmarks.dashboards.list', $dashboards );
|
||||
}
|
||||
|
||||
/**
|
||||
* Functionality
|
||||
*/
|
||||
@ -688,4 +877,47 @@ class Bookmarks extends Controller {
|
||||
$folderSelect = Template::parse( $out );
|
||||
Components::set( 'folderSelect', $folderSelect );
|
||||
}
|
||||
|
||||
private function setPrefToggles() {
|
||||
$prefsArray = [
|
||||
'editModeSwitch',
|
||||
'showArchivedSwitch',
|
||||
'showHiddenSwitch',
|
||||
'archiveButtonSwitch',
|
||||
'visibilityButtonSwitch',
|
||||
'privacyButtonSwitch',
|
||||
'shareButtonSwitch',
|
||||
'addButtonSwitch'
|
||||
];
|
||||
foreach ($prefsArray as $key => $name) {
|
||||
if ( empty( App::$activeUser->prefs[$name] ) ) {
|
||||
Components::set( $name . '_IS_CHECKED', '' );
|
||||
} else {
|
||||
Components::set( $name . '_IS_CHECKED', ' checked' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function setDashToggles( $current = [] ) {
|
||||
$prefsArray = [
|
||||
'editModeSwitch',
|
||||
'showArchivedSwitch',
|
||||
'showHiddenSwitch',
|
||||
'archiveButtonSwitch',
|
||||
'visibilityButtonSwitch',
|
||||
'privacyButtonSwitch',
|
||||
'shareButtonSwitch',
|
||||
'addButtonSwitch'
|
||||
];
|
||||
foreach ( $prefsArray as $key => $name ) {
|
||||
Debug::error( $name );
|
||||
Debug::error( $current );
|
||||
if ( ! in_array( $name, $current ) ) {
|
||||
Components::set( $name . '_IS_CHECKED', '' );
|
||||
} else {
|
||||
Debug::error( '_IS_CHECKED' );
|
||||
Components::set( $name . '_IS_CHECKED', ' checked' );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
65
app/plugins/bookmarks/controllers/extensions.php
Normal file
65
app/plugins/bookmarks/controllers/extensions.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* app/controllers/extensions.php
|
||||
*
|
||||
* This is the extensions 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;
|
||||
use TheTempusProject\Houdini\Classes\Issues;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
|
||||
class Extensions extends Controller {
|
||||
public function index() {
|
||||
self::$title = 'Browser Extensions';
|
||||
if ( App::$isLoggedIn ) {
|
||||
Issues::add( 'success', 'We also have a simple solution to using the app from your mobile devices <a href="/extensions/mobile">here</a>.' );
|
||||
}
|
||||
Views::view( 'bookmarks.extensions.index' );
|
||||
}
|
||||
|
||||
public function mobile() {
|
||||
self::$title = 'Mobile Bookmarklet';
|
||||
if ( App::$isLoggedIn ) {
|
||||
return Issues::add( 'error', 'Unfortunately you will need to sign in to generate the bookmarklet unique to your account.' );
|
||||
}
|
||||
Views::view( 'bookmarks.extensions.bookmarklet' );
|
||||
}
|
||||
|
||||
public function chrome() {
|
||||
self::$title = 'Chrome Extension';
|
||||
Views::view( 'bookmarks.extensions.chrome' );
|
||||
}
|
||||
|
||||
public function firefox() {
|
||||
self::$title = 'Firefox Extension';
|
||||
Views::view( 'bookmarks.extensions.firefox' );
|
||||
}
|
||||
|
||||
public function opera() {
|
||||
self::$title = 'Opera Extension';
|
||||
Views::view( 'bookmarks.extensions.opera' );
|
||||
}
|
||||
|
||||
public function edge() {
|
||||
self::$title = 'Edge Extension';
|
||||
Views::view( 'bookmarks.extensions.edge' );
|
||||
}
|
||||
|
||||
public function brave() {
|
||||
self::$title = 'Brave Extension';
|
||||
Views::view( 'bookmarks.extensions.brave' );
|
||||
}
|
||||
|
||||
public function safari() {
|
||||
self::$title = 'Safari Extension';
|
||||
Views::view( 'bookmarks.extensions.safari' );
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user