Skip to content

Commit f2b9795

Browse files
authored
Merge pull request #29 from Kovah/dev
v0.0.5
2 parents da1777f + e2a7d02 commit f2b9795

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+362
-33
lines changed

app/Helper/LinkIconMapper.php

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<?php
2+
3+
namespace App\Helper;
4+
5+
/**
6+
* Class LinkIconMapper
7+
*
8+
* @package App\Helper
9+
*/
10+
class LinkIconMapper
11+
{
12+
/** @var string Default icon as fallback if no specific icon was found */
13+
public static $default_icon = 'fa fa-link';
14+
15+
/** @var array Array holding the pattern => icon map, sorted alphabetically */
16+
public static $icon_map = [
17+
'500px\.com' => 'fab fa-500px',
18+
'adobe\.com' => 'fab fa-adobe',
19+
'aws\.amazon\.com' => 'fab fa-aws', // put before amazon pattern to keep it easy
20+
'amazon\.([a-zA-Z]*(\.)?[a-zA-Z]*)' => 'fab fa-amazon', // match amazon with every TLD
21+
'angel\.co' => 'fab fa-angellist',
22+
'itunes\.apple\.com\/app' => 'fab fa-app-store',
23+
'apple\.com' => 'fab fa-apple',
24+
'artstation\.com' => 'fab fa-artstation',
25+
'atlassian\.(com|net)' => 'fab fa-atlassian',
26+
'bandcamp\.com' => 'fab fa-bandcamp',
27+
'behance\.net' => 'fab fa-behance',
28+
'bitbucket\.org' => 'fab fa-bitbucket',
29+
'blockchain\.com' => 'fab fa-bitcoin',
30+
'blogger\.com' => 'fab fa-blogger-b',
31+
'chrome\.google\.com\/webstore' => 'fab fa-chrome',
32+
'codepen\.io' => 'fab fa-codepen',
33+
'dev\.to' => 'fab fa-dev',
34+
'deviantart\.com' => 'fab fa-deviantart',
35+
'digitalocean\.com' => 'fab fa-digital-ocean',
36+
'(discordapp\.com|discord\.gg)' => 'fab fa-discord',
37+
'meta\.discourse\.org' => 'fab fa-discourse',
38+
'docker\.com' => 'fab fa-docker',
39+
'dribbble\.com' => 'fab fa-dribbble',
40+
'dropbox\.com' => 'fab fa-dropbox',
41+
'drupal\.org' => 'fab fa-drupal',
42+
'ebay\.([a-zA-Z]*(\.)?[a-zA-Z]*)' => 'fab fa-ebay',
43+
'ello\.co' => 'fab fa-ello',
44+
'etsy\.com' => 'fab fa-etsy',
45+
'(facebook\.com|fb\.me)' => 'fab fa-facebook-f',
46+
'addons\.mozilla\.org\/[a-zA-Z-_]+\/firefox' => 'fab fa-firefox',
47+
'figma\.com' => 'fab fa-figma',
48+
'flickr\.com' => 'fab fa-flickr',
49+
'(flipboard\.com|flip\.it)' => 'fab fa-flipboard',
50+
'foursquare\.com' => 'fab fa-foursquare',
51+
'(getpocket\.com|pocket\.co)' => 'fab fa-get-pocket',
52+
'(github\.com|github\.io)' => 'fab fa-github',
53+
'gitlab\.com' => 'fab fa-gitlab',
54+
'gitter\.im' => 'fab fa-gitter',
55+
'drive\.google\.com' => 'fab fa-google-drive',
56+
'play\.google\.com' => 'fab fa-google-play',
57+
'google\.([a-zA-Z]*(\.)?[a-zA-Z]*)' => 'fab fa-google',
58+
'news\.ycombinator\.com' => 'fab fa-hacker-news',
59+
'hackerrank\.com' => 'fab fa-hackerrank',
60+
'houzz\.com' => 'fab fa-houzz',
61+
'imdb\.com' => 'fab fa-imdb',
62+
'instagram\.com' => 'fab fa-instagram',
63+
'invisionapp\.com' => 'fab fa-invision',
64+
'jsfiddle\.net' => 'fab fa-jsfiddle',
65+
'kaggle\.com' => 'fab fa-kaggle',
66+
'keybase\.io' => 'fab fa-keybase',
67+
'kickstarter\.com' => 'fab fa-kickstarter',
68+
'last\.fm' => 'fab fa-lastfm',
69+
'leanpub\.com' => 'fab fa-leanpub',
70+
'linkedin\.com' => 'fab fa-linkedin-in',
71+
'mastodon\.social' => 'fab fa-mastodon',
72+
'medium\.com' => 'fab fa-medium-m',
73+
'meetup\.com' => 'fab fa-meetup',
74+
'microsoft\.com' => 'fab fa-microsoft',
75+
'mixcloud\.com' => 'fab fa-mixcloud',
76+
'store\.nintendo\.com' => 'fab fa-nintendo-switch',
77+
'npmjs\.com' => 'fab fa-npm',
78+
'openid\.net' => 'fab fa-openid',
79+
'opensource\.org' => 'fab fa-osi',
80+
'patreon\.com' => 'fab fa-patreon ',
81+
'paypal\.([a-zA-Z]*(\.)?[a-zA-Z]*)' => 'fab fa-paypal',
82+
'periscope\.tv' => 'fab fa-periscope',
83+
'php\.net' => 'fab fa-php',
84+
'pinterest\.com' => 'fab fa-pinterest',
85+
'playstation\.com' => 'fab fa-playstation',
86+
'producthunt\.com' => 'fab fa-product-hunt',
87+
'python\.org' => 'fab fa-python',
88+
'quora\.com' => 'fab fa-quora',
89+
'readme\.io' => 'fab fa-readme',
90+
'reddit\.com' => 'fab fa-reddit',
91+
'researchgate\.net' => 'fab fa-researchgate',
92+
'rocket\.chat' => 'fab fa-rocketchat',
93+
'scribd\.com' => 'fab fa-scribd',
94+
'skype\.com' => 'fab fa-skype',
95+
'slack\.com' => 'fab fa-slack',
96+
'slideshare\.net' => 'fab fa-slideshare',
97+
'snapchat\.com' => 'fab fa-snapchat',
98+
'soundcloud\.com' => 'fab fa-soundcloud',
99+
'spotify\.com' => 'fab fa-spotify',
100+
'squarespace\.com' => 'fab fa-squarespace',
101+
'stackexchange\.com' => 'fab fa-stack-exchange',
102+
'stackoverflow\.com' => 'fab fa-stack-overflow',
103+
'(steampowered\.com|steamcommunity\.com)' => 'fab fa-steam',
104+
'strava\.com' => 'fab fa-strava',
105+
'(telegram\.org|t\.me)' => 'fab fa-telegram',
106+
'trello\.com' => 'fab fa-trello',
107+
'tripadvisor\.com' => 'fab fa-tripadvisor',
108+
'tumblr\.com' => 'fab fa-tumblr',
109+
'twitch\.tv' => 'fab fa-twitch',
110+
'twitter\.com' => 'fab fa-twitter',
111+
'vimeo\.com' => 'fab fa-vimeo',
112+
'weibo\.com' => 'fab fa-weibo',
113+
'wikipedia\.org' => 'fab fa-wikipedia-w',
114+
'wordpress\.com' => 'fab fa-wordpress',
115+
'wordpress\.org' => 'fab fa-wordpress-simple',
116+
'xbox\.com' => 'fab fa-xbox',
117+
'xing\.com' => 'fab fa-xing',
118+
'yahoo\.com' => 'fab fa-yahoo',
119+
'yelp\.com' => 'fab fa-yelp',
120+
'youtube\.com' => 'fab fa-youtube',
121+
];
122+
123+
/**
124+
* Check if the given url matches an icon
125+
*
126+
* @param $url
127+
* @return string
128+
*/
129+
public static function mapLink($url): string
130+
{
131+
foreach (self::$icon_map as $pattern => $icon) {
132+
if (preg_match('/' . $pattern . '/i', $url)) {
133+
return $icon;
134+
}
135+
}
136+
137+
return self::$default_icon;
138+
}
139+
}

app/Http/Controllers/App/DashboardController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class DashboardController extends Controller
1515
public function index()
1616
{
1717
$recent_links = Link::byUser(auth()->user()->id)
18-
->orderBy('created_at', 'asc')
18+
->orderBy('created_at', 'DESC')
1919
->limit(10)
2020
->get();
2121

app/Http/Controllers/App/ImportController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Http\Controllers\App;
44

55
use App\Helper\LinkAce;
6+
use App\Helper\LinkIconMapper;
67
use App\Http\Controllers\Controller;
78
use App\Http\Requests\DoImportRequest;
89
use App\Models\Link;
@@ -59,6 +60,7 @@ public function doImport(DoImportRequest $request)
5960
'url' => $link['uri'],
6061
'title' => $title,
6162
'description' => $link['note'],
63+
'icon' => LinkIconMapper::mapLink($link['uri']),
6264
'is_private' => $link['pub'],
6365
'created_at' => Carbon::createFromTimestamp($link['time']),
6466
'updated_at' => Carbon::now(),

app/Http/Controllers/Models/LinkController.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Http\Controllers\Models;
44

55
use App\Helper\LinkAce;
6+
use App\Helper\LinkIconMapper;
67
use App\Http\Controllers\Controller;
78
use App\Http\Requests\LinkDeleteRequest;
89
use App\Http\Requests\LinkStoreRequest;
@@ -70,6 +71,7 @@ public function store(LinkStoreRequest $request)
7071

7172
// Set the user ID
7273
$data['user_id'] = auth()->user()->id;
74+
$data['icon'] = LinkIconMapper::mapLink($data['url']);
7375

7476
$data['category_id'] = isset($data['category_id']) && $data['category_id'] > 0 ?: null;
7577

@@ -183,7 +185,10 @@ public function update(LinkUpdateRequest $request, $id)
183185
}
184186

185187
// Update the existing link with new data
186-
$link->update($request->except('tags'));
188+
$data = $request->except('tags');
189+
$data['icon'] = LinkIconMapper::mapLink($data['url']);
190+
191+
$link->update($data);
187192

188193
Link::flushCache();
189194

app/Models/Category.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
namespace App\Models;
44

5+
use App\Scopes\OrderNameScope;
56
use Illuminate\Database\Eloquent\Builder;
67
use Illuminate\Database\Eloquent\Collection;
78
use Illuminate\Database\Eloquent\SoftDeletes;
8-
use App\Models\Link;
9-
use App\Models\User;
109

1110
/**
1211
* Class Category
@@ -27,7 +26,7 @@
2726
* @method static Builder|Category parentOnly()
2827
* @method static Builder|Category byUser($user_id)
2928
*/
30-
class Category extends Model
29+
class Category extends RememberedModel
3130
{
3231
use SoftDeletes;
3332

@@ -43,6 +42,16 @@ class Category extends Model
4342

4443
public $rememberCacheTag = 'category_queries';
4544

45+
/**
46+
* Add the OrderNameScope to the Tag model
47+
*/
48+
protected static function boot()
49+
{
50+
parent::boot();
51+
52+
static::addGlobalScope(new OrderNameScope());
53+
}
54+
4655
/*
4756
| ========================================================================
4857
| SCOPES

app/Models/Link.php

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* @property string $url
1717
* @property string $title
1818
* @property string|null $description
19+
* @property string|null $icon
1920
* @property int $is_private
2021
* @property \Carbon\Carbon|null $created_at
2122
* @property \Carbon\Carbon|null $updated_at
@@ -26,7 +27,7 @@
2627
* @property-read User $user
2728
* @method static Builder|Link byUser($user_id)
2829
*/
29-
class Link extends Model
30+
class Link extends RememberedModel
3031
{
3132
use SoftDeletes;
3233

@@ -38,6 +39,7 @@ class Link extends Model
3839
'url',
3940
'title',
4041
'description',
42+
'icon',
4143
'is_private',
4244
];
4345

@@ -51,8 +53,8 @@ class Link extends Model
5153
/**
5254
* Scope for the user relation
5355
*
54-
* @param \Illuminate\Database\Eloquent\Builder $query
55-
* @param int $user_id
56+
* @param Builder $query
57+
* @param int $user_id
5658
* @return mixed
5759
*/
5860
public function scopeByUser($query, $user_id)
@@ -82,31 +84,31 @@ public function scopePrivateOnly($query, bool $is_private)
8284
*/
8385
public function user()
8486
{
85-
return $this->belongsTo('App\Models\User', 'user_id');
87+
return $this->belongsTo(User::class, 'user_id');
8688
}
8789

8890
/**
8991
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
9092
*/
9193
public function category()
9294
{
93-
return $this->belongsTo('App\Models\Category', 'category_id');
95+
return $this->belongsTo(Category::class, 'category_id');
9496
}
9597

9698
/**
9799
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
98100
*/
99101
public function tags()
100102
{
101-
return $this->belongsToMany('App\Models\Tag', 'link_tags', 'link_id', 'tag_id');
103+
return $this->belongsToMany(Tag::class, 'link_tags', 'link_id', 'tag_id');
102104
}
103105

104106
/**
105107
* @return \Illuminate\Database\Eloquent\Relations\HasMany
106108
*/
107109
public function notes()
108110
{
109-
return $this->hasMany('App\Models\Note', 'link_id');
111+
return $this->hasMany(Note::class, 'link_id');
110112
}
111113

112114
/*
@@ -128,6 +130,21 @@ public function tagsForInput()
128130
return $tags->implode('name', ',');
129131
}
130132

133+
/**
134+
* @param $additional_classes
135+
* @return string
136+
*/
137+
public function getIcon($additional_classes = null): string
138+
{
139+
if ($this->icon === null) {
140+
return '';
141+
}
142+
143+
$classes = 'fa-fw ' . $this->icon . ($additional_classes ? ' ' . $additional_classes : '');
144+
145+
return '<i class="' . $classes . '"></i>';
146+
}
147+
131148
/**
132149
* Output a relative time inside a span with real time information
133150
*

app/Models/Note.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* @property-read User $user
2222
* @method static Builder|Link byUser($user_id)
2323
*/
24-
class Note extends Model
24+
class Note extends RememberedModel
2525
{
2626
use SoftDeletes;
2727

app/Models/Model.php renamed to app/Models/RememberedModel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
namespace App\Models;
44

5-
use Illuminate\Database\Eloquent\Model as Eloquent;
5+
use Illuminate\Database\Eloquent\Model as BaseModel;
66
use Watson\Rememberable\Rememberable;
77

88
/**
99
* Class Model
1010
*
1111
* @package App\Models
1212
*/
13-
abstract class Model extends Eloquent
13+
abstract class RememberedModel extends BaseModel
1414
{
1515
use Rememberable;
1616

app/Models/Tag.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Models;
44

5+
use App\Scopes\OrderNameScope;
56
use Illuminate\Database\Eloquent\Builder;
67
use Illuminate\Database\Eloquent\Collection;
78
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -21,7 +22,7 @@
2122
* @property-read User $user
2223
* @method static Builder|Tag byUser($user_id)
2324
*/
24-
class Tag extends Model
25+
class Tag extends RememberedModel
2526
{
2627
use SoftDeletes;
2728

@@ -35,6 +36,16 @@ class Tag extends Model
3536

3637
public $rememberCacheTag = 'tag_queries';
3738

39+
/**
40+
* Add the OrderNameScope to the Tag model
41+
*/
42+
protected static function boot()
43+
{
44+
parent::boot();
45+
46+
static::addGlobalScope(new OrderNameScope());
47+
}
48+
3849
/*
3950
| ========================================================================
4051
| SCOPES

0 commit comments

Comments
 (0)