Add bookmark exports and sharing + various fixes
This commit is contained in:
127
app/plugins/bookmarks/controllers/shared.php
Normal file
127
app/plugins/bookmarks/controllers/shared.php
Normal file
@ -0,0 +1,127 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/bookmarks/controllers/shared.php
|
||||
*
|
||||
* This is the bug reports controller.
|
||||
*
|
||||
* @package TP Bookmarks
|
||||
* @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\Houdini\Classes\Views;
|
||||
use TheTempusProject\Classes\Controller;
|
||||
use TheTempusProject\Models\Bookmarks as Bookmark;
|
||||
use TheTempusProject\Models\Folders;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
use TheTempusProject\Houdini\Classes\Components;
|
||||
use TheTempusProject\Hermes\Functions\Route as Routes;
|
||||
|
||||
class Shared extends Controller {
|
||||
protected static $bookmarks;
|
||||
protected static $folders;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$bookmarks = new Bookmark;
|
||||
self::$folders = new Folders;
|
||||
self::$title = 'Bookmarks - {SITENAME}';
|
||||
self::$pageDescription = 'Add and save url bookmarks here.';
|
||||
Components::set( 'SITE_URL', Routes::getAddress() );
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$bookmarks = self::$bookmarks->noFolder();
|
||||
$folders = self::$folders->byUser();
|
||||
|
||||
$panelArray = [];
|
||||
if ( !empty( $folders ) ) {
|
||||
foreach ( $folders as $folder ) {
|
||||
$panel = new \stdClass();
|
||||
$folderObject = new \stdClass();
|
||||
$folderObject->bookmarks = self::$bookmarks->byFolder( $folder->ID );
|
||||
$folderObject->ID = $folder->ID;
|
||||
$folderObject->title = $folder->title;
|
||||
$folderObject->color = $folder->color;
|
||||
$folderObject->bookmarkListRows = Views::simpleView( 'bookmarks.components.bookmarkListRows', $folderObject->bookmarks );
|
||||
$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' );
|
||||
}
|
||||
|
||||
public function shared( $type = '', $id = '' ) {
|
||||
if ( empty( $type ) ) {
|
||||
Session::flash( 'error', 'Unknown share' );
|
||||
return Redirect::to( 'home/index' );
|
||||
}
|
||||
|
||||
if ( empty( $id ) ) {
|
||||
Session::flash( 'error', 'Unknown share' );
|
||||
return Redirect::to( 'home/index' );
|
||||
}
|
||||
|
||||
$type = strtolower( $type );
|
||||
if ( ! in_array( $type, ['link','folder'] ) ) {
|
||||
Session::flash( 'error', 'Unknown share' );
|
||||
return Redirect::to( 'home/index' );
|
||||
}
|
||||
|
||||
$this->$type( $id );
|
||||
}
|
||||
|
||||
public function link( $id = '' ) {
|
||||
if ( empty( $id ) ) {
|
||||
Session::flash( 'error', 'Unknown share' );
|
||||
return Redirect::to( 'home/index' );
|
||||
}
|
||||
$bookmark = self::$bookmarks->findByUuid( $id );
|
||||
if ( $bookmark == false ) {
|
||||
Session::flash( 'error', 'Unknown share' );
|
||||
return Redirect::to( 'home/index' );
|
||||
}
|
||||
if ( $bookmark->createdBy != App::$activeUser->ID ) {
|
||||
if ( $bookmark->privacy == 'private' ) {
|
||||
if ( empty( $bookmark->folderID ) ) {
|
||||
Session::flash( 'error', 'Unknown share' );
|
||||
return Redirect::to( 'home/index' );
|
||||
}
|
||||
$folder = self::$folders->findByUuid( $bookmark->folderID );
|
||||
if ( $folder == false ) {
|
||||
Session::flash( 'error', 'Unknown share' );
|
||||
return Redirect::to( 'home/index' );
|
||||
}
|
||||
if ( $folder->privacy == 'private' ) {
|
||||
Session::flash( 'error', 'Unknown share' );
|
||||
return Redirect::to( 'home/index' );
|
||||
}
|
||||
}
|
||||
}
|
||||
return Views::view( 'bookmarks.shareLink', $bookmark );
|
||||
}
|
||||
|
||||
public function folder( $id = '' ) {
|
||||
if ( empty( $id ) ) {
|
||||
Session::flash( 'error', 'Unknown share' );
|
||||
return Redirect::to( 'home/index' );
|
||||
}
|
||||
$folder = self::$folders->findByUuid( $id );
|
||||
if ( $folder == false ) {
|
||||
Session::flash( 'error', 'Unknown share' );
|
||||
return Redirect::to( 'home/index' );
|
||||
}
|
||||
if ( $folder->privacy == 'private' ) {
|
||||
Session::flash( 'error', 'Unknown share' );
|
||||
return Redirect::to( 'home/index' );
|
||||
}
|
||||
return Views::view( 'bookmarks.shareFolder', $folder );
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user