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

@ -41,7 +41,7 @@ class BookmarkDashboards extends DatabaseModel {
public function create( $title, $saved_prefs, $link_order, $description = '' ) {
if ( ! Check::dataTitle( $title ) ) {
Debug::info( 'Views: illegal title.' );
Debug::info( 'Dash: illegal title.' );
return false;
}
$fields = [
@ -54,8 +54,8 @@ class BookmarkDashboards extends DatabaseModel {
'createdAt' => time(),
];
if ( ! self::$db->insert( $this->tableName, $fields ) ) {
new CustomException( 'viewCreate' );
Debug::error( "Views: not created " . var_export($fields,true) );
new CustomException( 'dashCreate' );
Debug::error( "Dash: not created " . var_export($fields,true) );
return false;
}
return self::$db->lastId();
@ -63,11 +63,11 @@ class BookmarkDashboards extends DatabaseModel {
public function update( $id, $title, $saved_prefs, $link_order, $description = '' ) {
if ( !Check::id( $id ) ) {
Debug::info( 'Views: illegal ID.' );
Debug::info( 'Dash: illegal ID.' );
return false;
}
if ( !Check::dataTitle( $title ) ) {
Debug::info( 'Views: illegal title.' );
Debug::info( 'Dash: illegal title.' );
return false;
}
$fields = [
@ -77,8 +77,29 @@ class BookmarkDashboards extends DatabaseModel {
'link_order' => $link_order,
];
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
new CustomException( 'viewUpdate' );
Debug::error( "Views: $id not updated" );
new CustomException( 'dashUpdate' );
Debug::error( "Dash: $id not updated" );
return false;
}
return true;
}
public function updateDash( $id, $saved_prefs = '', $link_order = '' ) {
if ( !Check::id( $id ) ) {
Debug::info( 'Dash: illegal ID.' );
return false;
}
$fields = [];
$fields['saved_prefs'] = $saved_prefs;
if ( ! empty( $link_order ) ) {
$fields['link_order'] = $link_order;
}
if ( empty( $fields ) ) {
return true;
}
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
new CustomException( 'dashUpdate' );
Debug::error( "Dash: $id not updated" );
return false;
}
return true;

View File

@ -146,16 +146,17 @@ class Bookmarks extends DatabaseModel {
return $this->filter( $bookmarks->results() );
}
public function byFolder( $id, $limit = null ) {
$whereClause = ['createdBy', '=', App::$activeUser->ID, 'AND'];
$whereClause = array_merge( $whereClause, [ 'folderID', '=', $id ] );
if ( empty( $limit ) ) {
$bookmarks = self::$db->get( $this->tableName, $whereClause );
} else {
$bookmarks = self::$db->get( $this->tableName, $whereClause, 'ID', 'DESC', [0, $limit] );
public function byFolder( $id, $hiddenExcluded = false, $archivedExcluded = false ) {
$whereClause = ['createdBy', '=', App::$activeUser->ID ];
$whereClause = array_merge( $whereClause, [ 'AND', 'folderID', '=', $id ] );
if ( ! empty( $hiddenExcluded ) ) {
$whereClause = array_merge( $whereClause, [ 'AND', 'hiddenAt', 'is', 'NULL'] );
}
if ( !$bookmarks->count() ) {
if ( ! empty( $archivedExcluded ) ) {
$whereClause = array_merge( $whereClause, [ 'AND', 'archivedAt', 'is', 'NULL'] );
}
$bookmarks = self::$db->get( $this->tableName, $whereClause );
if ( ! $bookmarks->count() ) {
Debug::info( 'No Bookmarks found.' );
return false;
}
@ -343,17 +344,18 @@ class Bookmarks extends DatabaseModel {
$instance = $data;
$end = true;
}
$base_url = $this->getBaseUrl( $instance->url );
if ( empty( $instance->icon ) ) {
$instance->iconHtml = '<i class="fa fa-fw fa-link"></i>';
} else {
if (strpos($instance->icon, 'http') !== false) {
$instance->iconHtml = '<img src="' . $instance->icon .'">';
} else {
$instance->iconHtml = '<img src="' . $base_url . ltrim( $instance->icon, '/' ) .'">';
$instance->iconHtml = '<i class="fa fa-fw fa-link"></i>';
if ( ! empty( $instance->icon ) ) {
if ( strpos($instance->icon, 'http') !== false) {
$instance->iconHtml = '<img src="' . $instance->icon .'">';
} else {
if ( ! empty( $instance->url ) ) {
$base_url = $this->getBaseUrl( $instance->url );
$instance->iconHtml = '<img src="' . $base_url . ltrim( $instance->icon, '/' ) .'">';
}
}
}
}
if ( $instance->privacy == 'private' ) {
$instance->privacyBadge = '<span class="mx-2 translate-center badge bg-success rounded-pill">Private</span>';
@ -439,7 +441,7 @@ class Bookmarks extends DatabaseModel {
return false;
}
$fields = [
'hiddenAt' => 0,
'hiddenAt' => NULL,
];
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
new CustomException( 'bookmarkUpdate' );
@ -503,7 +505,7 @@ class Bookmarks extends DatabaseModel {
return false;
}
$fields = [
'archivedAt' => 0,
'archivedAt' => NULL,
];
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
new CustomException( 'bookmarkUpdate' );
@ -779,7 +781,7 @@ class Bookmarks extends DatabaseModel {
}
}
function isValidImageUrl($url) {
public function isValidImageUrl($url) {
$headers = @get_headers($url);
if ($headers && strpos($headers[0], '200') !== false) {