Skip to content

Commit e0769d5

Browse files
authored
Merge pull request #31 from Kovah/dev
v0.0.6
2 parents f2b9795 + ae6b93a commit e0769d5

File tree

24 files changed

+292
-112
lines changed

24 files changed

+292
-112
lines changed

.env.docker

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ DB_USERNAME=linkace
3232
DB_PASSWORD=changeThisPassword
3333

3434
## Configure user session details
35-
# Set the time after a session expires automatically, in minutes
36-
SESSION_LIFETIME=120
35+
# Set the time after a session expires automatically, in minutes. Default is 7 days.
36+
SESSION_LIFETIME=10080
3737

3838
## Mail configuration
3939
MAIL_DRIVER=smtp

.env.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ DB_USERNAME=linkace
3232
DB_PASSWORD=changeThisPassword
3333

3434
## Configure user session details
35-
# Set the time after a session expires automatically, in minutes
36-
SESSION_LIFETIME=120
35+
# Set the time after a session expires automatically, in minutes. Default is 7 days.
36+
SESSION_LIFETIME=10080
3737

3838
## Mail configuration
3939
MAIL_DRIVER=smtp

app/Helper/LinkAce.php

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,57 @@
1010
class LinkAce
1111
{
1212
/**
13-
* Get the title of an HTML page b
13+
* Get the title and description of a website form it's URL
1414
*
1515
* @param string $url
1616
* @return string|string[]
1717
*/
18-
public static function getTitleFromURL(string $url)
18+
public static function getMetaFromURL(string $url)
1919
{
20-
$fail_return = parse_url($url, PHP_URL_HOST);
20+
$title_fallback = parse_url($url, PHP_URL_HOST);
2121

22+
$fallback = [
23+
'title' => $title_fallback,
24+
'description' => null,
25+
];
26+
27+
// Try to get the HTML content of that URL
2228
try {
23-
$fp = file_get_contents($url);
29+
$html = file_get_contents($url);
2430
} catch (\Exception $e) {
25-
return $fail_return;
31+
return $fallback;
2632
}
2733

28-
if (!$fp) {
29-
return $fail_return;
34+
if (!$html) {
35+
return $fallback;
3036
}
3137

32-
$res = preg_match("/<title>(.*)<\/title>/siU", $fp, $title_matches);
38+
// Parse the HTML for the title
39+
$res = preg_match("/<title>(.*)<\/title>/siU", $html, $title_matches);
3340

34-
if (!$res) {
35-
return $fail_return;
41+
if ($res) {
42+
// Clean up title: remove EOL's and excessive whitespace.
43+
$title = preg_replace('/\s+/', ' ', $title_matches[1]);
44+
$title = trim($title);
3645
}
3746

38-
// Clean up title: remove EOL's and excessive whitespace.
39-
$title = preg_replace('/\s+/', ' ', $title_matches[1]);
40-
$title = trim($title);
47+
// Parse the HTML for the meta description, or alternatively for the og:description property
48+
$res = preg_match(
49+
'/<meta (?:property="og:description"|name="description") content="(.*?)"(?:\s\/)?>/i',
50+
$html,
51+
$description_matches
52+
);
53+
54+
if ($res) {
55+
// Clean up description: remove EOL's and excessive whitespace.
56+
$description = preg_replace('/\s+/', ' ', $description_matches[1]);
57+
$description = trim($description);
58+
}
4159

42-
return $title;
60+
return [
61+
'title' => $title ?? $title_fallback,
62+
'description' => $description ?? null,
63+
];
4364
}
4465

4566
/**
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\App;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Models\Link;
7+
use Illuminate\Http\Request;
8+
9+
class ExportController extends Controller
10+
{
11+
/**
12+
* Show the application dashboard.
13+
*
14+
* @return \Illuminate\Http\Response
15+
*/
16+
public function getExport()
17+
{
18+
return view('actions.export.export');
19+
}
20+
21+
/**
22+
* Permanently delete entries for a model from the trash
23+
*
24+
* @param Request $request
25+
* @return \Illuminate\Http\Response
26+
*/
27+
public function doExport(Request $request)
28+
{
29+
$links = Link::orderBy('title', 'asc')->get();
30+
31+
$file_content = view()->make('actions.export.exportfile', ['links' => $links])->render();
32+
$file_name = config('app.name') . '_export.html';
33+
34+
return response()->streamDownload(function () use ($file_content) {
35+
echo $file_content;
36+
}, $file_name);
37+
}
38+
}

app/Http/Controllers/App/ImportController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,16 @@ public function doImport(DoImportRequest $request)
5252
$skipped++;
5353
} else {
5454

55-
$title = $link['title'] ?: LinkAce::getTitleFromURL($link['uri']);
55+
$link_meta = LinkAce::getMetaFromURL($link['uri']);
56+
57+
$title = $link['title'] ?: $link_meta['title'];
5658

5759
$new_link = Link::create([
5860
'user_id' => $user_id,
5961
'category_id' => null,
6062
'url' => $link['uri'],
6163
'title' => $title,
62-
'description' => $link['note'],
64+
'description' => $link['note'] ?: $link_meta['description'],
6365
'icon' => LinkIconMapper::mapLink($link['uri']),
6466
'is_private' => $link['pub'],
6567
'created_at' => Carbon::createFromTimestamp($link['time']),

app/Http/Controllers/Models/LinkController.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,17 @@ public function store(LinkStoreRequest $request)
6666
// Save the new link
6767
$data = $request->except(['tags', 'reload_view']);
6868

69-
// Try to get the <title> of the URL if no title was provided
70-
$data['title'] = $data['title'] ?? LinkAce::getTitleFromURL($data['url']);
69+
// Try to get the meta information of the URL if no title / description was provided
70+
$link_meta = LinkAce::getMetaFromURL($data['url']);
71+
72+
$data['title'] = $data['title'] ?: $link_meta['title'];
73+
$data['description'] = $data['description'] ?: $link_meta['description'];
7174

7275
// Set the user ID
7376
$data['user_id'] = auth()->user()->id;
7477
$data['icon'] = LinkIconMapper::mapLink($data['url']);
7578

76-
$data['category_id'] = isset($data['category_id']) && $data['category_id'] > 0 ?: null;
79+
$data['category_id'] = isset($data['category_id']) && $data['category_id'] > 0 ? $data['category_id'] : null;
7780

7881
// Create the new link
7982
$link = Link::create($data);

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "A small, selfhosted bookmark manager with advanced features, built with Laravel and Docker",
44
"license": "MIT",
55
"type": "project",
6-
"version": "0.0.5",
6+
"version": "0.0.6",
77
"require": {
88
"php": "^7.1.3",
99
"doctrine/dbal": "^2.8",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "linkace",
3-
"version": "0.0.5",
3+
"version": "0.0.6",
44
"description": "A small, selfhosted bookmark manager with advanced features, built with Laravel and Docker",
55
"homepage": "https://github.com/Kovah/LinkAce",
66
"repository": {

resources/assets/sass/third-party/bootstrap/_variables.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,8 @@ $input-btn-padding-x: .75rem !default;
389389
$input-btn-font-size: $font-size-base !default;
390390
$input-btn-line-height: $line-height-base !default;
391391

392-
$input-btn-focus-width: .2rem !default;
393-
$input-btn-focus-color: rgba($component-active-bg, .25) !default;
392+
$input-btn-focus-width: .15rem !default;
393+
$input-btn-focus-color: rgba($component-active-bg, .15) !default;
394394
$input-btn-focus-box-shadow: 0 0 0 $input-btn-focus-width $input-btn-focus-color !default;
395395

396396
$input-btn-padding-y-xs: .15rem !default;

resources/lang/en/export.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
return [
3+
'export' => 'Export',
4+
'start_export' => 'Start Export',
5+
6+
'export_help' => 'Running the export will save all existing bookmarks into a regular bookmarks-compatible file.',
7+
];

0 commit comments

Comments
 (0)