This commit is contained in:
Joey Kimsey
2024-12-21 16:26:05 -05:00
parent 0c2fa757dd
commit f8e75e847d
59 changed files with 861 additions and 387 deletions

View File

@ -71,6 +71,7 @@ class Bookmarks extends Controller {
}
public function index() {
self::$title = 'Manage Bookmarks - {SITENAME}';
if ( Input::exists('submit') ) {
$prefs = new Preferences;
$user = new User;
@ -116,6 +117,7 @@ class Bookmarks extends Controller {
}
public function unsorted() {
self::$title = 'Unsorted Bookmarks - {SITENAME}';
$bookmarks = self::$bookmarks->noFolder();
Views::view( 'bookmarks.bookmarks.unsorted', $bookmarks );
}
@ -147,6 +149,7 @@ class Bookmarks extends Controller {
}
public function createBookmark( $id = null ) {
self::$title = 'Add Bookmark - {SITENAME}';
$folderID = Input::get('folder_id') ? Input::get('folder_id') : $id;
$folderID = Input::post('folder_id') ? Input::post('folder_id') : $id;
$this->setFolderSelect( $folderID );
@ -182,6 +185,7 @@ class Bookmarks extends Controller {
}
public function editBookmark( $id = null ) {
self::$title = 'Edit Bookmark - {SITENAME}';
$folderID = Input::exists('folder_id') ? Input::post('folder_id') : '';
$bookmark = self::$bookmarks->findById( $id );
@ -263,6 +267,7 @@ class Bookmarks extends Controller {
}
public function createFolder( $id = 0 ) {
self::$title = 'Create Folder - {SITENAME}';
$folderID = Input::exists('folder_id') ? Input::post('folder_id') : $id;
$folders = self::$folders->simpleByUser();
if ( ! empty( $folders ) ) {
@ -287,6 +292,7 @@ class Bookmarks extends Controller {
}
public function editFolder( $id = null ) {
self::$title = 'Edit Folder - {SITENAME}';
$folder = self::$folders->findById( $id );
if ( $folder == false ) {
@ -345,6 +351,11 @@ class Bookmarks extends Controller {
* Dashboards
*/
public function addDash() {
self::$title = 'Add Dashboard - {SITENAME}';
if ( !App::$isMember ) {
Issues::add( 'notice', 'You must have an active membership to add dashboards.' );
return $this->index();
}
$folders = self::$folders->byUser() ?? [];
if ( !empty( $folders ) ) {
@ -387,6 +398,11 @@ class Bookmarks extends Controller {
}
public function editDash( $id = null ) {
self::$title = 'Edit Dashboard - {SITENAME}';
if ( !App::$isMember ) {
Issues::add( 'notice', 'You must have an active membership to edit dashboards.' );
return $this->index();
}
$dash = self::$dashboards->findById( $id );
if ( $dash == false ) {
@ -449,6 +465,10 @@ class Bookmarks extends Controller {
}
public function deleteDash( $id = null ) {
if ( !App::$isMember ) {
Issues::add( 'notice', 'You must have an active membership to delete dashboards.' );
return $this->index();
}
$dash = self::$dashboards->findById( $id );
if ( $dash == false ) {
Issues::add( 'error', 'Unknown Dashboard' );
@ -468,6 +488,11 @@ class Bookmarks extends Controller {
}
public function dashboard( $uuid = null ) {
self::$title = 'Bookmark Dashboard - {SITENAME}';
if ( !App::$isMember ) {
Issues::add( 'notice', 'You must have an active membership to view dashboards.' );
return $this->index();
}
$dash = self::$dashboards->findByUuid( $uuid );
if ( $dash == false ) {
return $this->dashboards();
@ -476,6 +501,32 @@ class Bookmarks extends Controller {
Issues::add( 'error', 'You do not have permission to view this dash.' );
return $this->dashboards();
}
if ( Input::exists( 'submit' ) ) {
if ( Forms::check( 'updateDashboard' ) ) {
$filters = '';
$folders = '';
if ( is_array( Input::post('link_filter') ) && ! empty( Input::post('link_filter') ) ) {
$filters = implode( ',', Input::post('link_filter') );
}
if ( ! empty( Input::post('link_order') ) ) {
$folders = Input::post('link_order');
}
$result = self::$dashboards->updateDash( $dash->ID, $filters, $folders );
if ( !$result ) {
Issues::add( 'error', [ 'There was an error saving your dashboard.' => Check::userErrors() ] );
} else {
Issues::add( 'success', 'Your dashboard has been saved.' );
}
} else {
Issues::add( 'error', [ 'There was an error saving your dashboard.' => Check::userErrors() ] );
}
unset( $_POST );
}
$dash = self::$dashboards->findByUuid( $uuid );
$foldersArray = [];
if ( ! empty( $dash->link_order ) ) {
@ -504,12 +555,19 @@ class Bookmarks extends Controller {
if ( ! empty( $dash->saved_prefs ) ) {
$this->setDashToggles( explode( ',', $dash->saved_prefs ) );
} else {
$this->setDashToggles( [] );
}
return Views::view( 'bookmarks.dashboards.view', $dash );
}
public function dashboards() {
self::$title = 'Bookmark Dashboards - {SITENAME}';
if ( !App::$isMember ) {
Issues::add( 'notice', 'You must have an active membership to manage dashboards.' );
return $this->index();
}
$dashboards = self::$dashboards->byUser();
return Views::view( 'bookmarks.dashboards.list', $dashboards );
}
@ -517,7 +575,7 @@ class Bookmarks extends Controller {
/**
* Functionality
*/
public function publish( $id = null ) {
public function publish( $id = null ) {
$bookmark = self::$bookmarks->findById( $id );
if ( $bookmark == false ) {
Session::flash( 'error', 'Bookmark not found.' );
@ -627,6 +685,7 @@ class Bookmarks extends Controller {
}
public function import() {
self::$title = 'Bookmark Import - {SITENAME}';
if ( !App::$isMember ) {
Issues::add( 'notice', 'You must have an active membership to import bookmarks.' );
return $this->index();
@ -641,50 +700,44 @@ class Bookmarks extends Controller {
return Views::view( 'bookmarks.import' );
}
if (isset($_FILES['bookmark_file'])) {
if ( isset( $_FILES['bookmark_file'] ) ) {
$file = $_FILES['bookmark_file'];
// Check file size
if ($file['size'] > 1024 * 1024) { // 1024 KB = 1 MB
die('The file is too large. Maximum size is 1 MB.');
Issues::add( 'error', 'There is a 1 meg limit on bookmark imports at this time.' );
return Views::view( 'bookmarks.import' );
}
// Check file extension
$fileExtension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
if ($fileExtension !== 'html') {
die('Invalid file type. Only .html files are allowed.');
Issues::add( 'error', 'Invalid file type. Only .html files are allowed.' );
return Views::view( 'bookmarks.import' );
}
// Proceed with file processing
$fileContent = file_get_contents($file['tmp_name']);
} else {
die('No file was uploaded.');
Issues::add( 'error', 'No Import detected' );
return Views::view( 'bookmarks.import' );
}
$out = $this->parseBookmarks($fileContent);
$date = 'today';
$date = date('F j, Y');
$description = 'Imported on ' . $date . ' from file: ' . $file['name'];
$importFolder = self::$folders->create( 'New Import', 0, $description );
// $importFolder = 1;
// echo 'make import folder: ' . PHP_EOL;
foreach ($out as $folder => $bookmarks) {
// echo 'make folder: ' . $folder . PHP_EOL;
$currentFolder = self::$folders->create( $folder, $importFolder, $description );
foreach ($bookmarks as $index => $bookmark) {
// echo 'make folder: ' . $bookmark['url'] . PHP_EOL;
self::$bookmarks->create( $bookmark['name'], $bookmark['url'], $currentFolder);
}
}
Session::flash( 'success', 'Your Bookmark has been created.' );
Redirect::to( 'bookmarks/bookmarks/'. $importFolder );
// echo '</pre>';
// exit;
// dv ( $out );
}
public function export() {
self::$title = 'Bookmark Export - {SITENAME}';
if ( !App::$isMember ) {
Issues::add( 'notice', 'You must have an active membership to export bookmarks.' );
return $this->index();
@ -720,7 +773,11 @@ class Bookmarks extends Controller {
Session::flash( 'error', 'Folder not found.' );
return Redirect::to( 'bookmarks/index' );
}
$links = self::$bookmarks->byFolder( $folder->ID );
$hiddenExcluded = ! ( Input::post('hiddenIncluded') ?? false );
$archivedExcluded = ! ( Input::post('archivedIncluded') ?? false );
$links = self::$bookmarks->byFolder( $folder->ID, $hiddenExcluded, $archivedExcluded );
$htmlDoc .= $this->exportFolder( $folder->title, $folder->createdAt, $folder->createdAt, $links );
}
$htmlDoc .= '</DL><p>' . PHP_EOL;
@ -774,6 +831,10 @@ class Bookmarks extends Controller {
return Views::view( 'bookmarks.share', $panelArray );
}
/**
* Private
*/
private function exportFolder( $title, $editedAt, $createdAt, $links ) {
$htmlDoc = '<DT><H3 ADD_DATE="'.$createdAt.'" LAST_MODIFIED="'.$editedAt.'">'.$title.'</H3>' . PHP_EOL;
$htmlDoc .= '<DL><p>' . PHP_EOL;