Skip to content

Commit d2ce9e0

Browse files
authored
Merge pull request #114 from Hyleus/url-matcher
Replace the URL matcher everywhere
2 parents 5ad18bb + 25d75d8 commit d2ce9e0

10 files changed

+63
-84
lines changed

app/Article.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
namespace App;
1414

1515
use Illuminate\Database\Eloquent\Model;
16-
use Decoda\Decoda;
16+
use App\Helpers\Bbcode;
1717

1818
class Article extends Model
1919
{
@@ -84,12 +84,6 @@ public function getBrief($length = 100, $ellipses = true, $strip_html = false)
8484
*/
8585
public function getContentHtml()
8686
{
87-
$code = new Decoda($this->content);
88-
$code->defaults();
89-
$code->removeHook('Censor');
90-
$code->setXhtml(false);
91-
$code->setStrict(false);
92-
$code->setLineBreaks(true);
93-
return $code->parse();
87+
return Bbcode::parse($this->content);
9488
}
9589
}

app/Comment.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
namespace App;
1414

1515
use Illuminate\Database\Eloquent\Model;
16-
use Decoda\Decoda;
16+
use App\Helpers\Bbcode;
1717

1818
class Comment extends Model
1919
{
@@ -60,13 +60,7 @@ public function user()
6060
*/
6161
public function getContentHtml()
6262
{
63-
$code = new Decoda($this->content);
64-
$code->defaults();
65-
$code->removeHook('Censor');
66-
$code->setXhtml(false);
67-
$code->setStrict(false);
68-
$code->setLineBreaks(true);
69-
return $code->parse();
63+
return Bbcode::parse($this->content);
7064
}
7165

7266
}

app/Helpers/Bbcode.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* NOTICE OF LICENSE
4+
*
5+
* UNIT3D is open-sourced software licensed under the GNU General Public License v3.0
6+
* The details is bundled with this project in the file LICENSE.txt.
7+
*
8+
* @project UNIT3D
9+
* @license https://choosealicense.com/licenses/gpl-3.0/ GNU General Public License v3.0
10+
* @author Ryuu
11+
*/
12+
13+
namespace App\Helpers;
14+
15+
use Decoda\Decoda;
16+
use App\Hook\ClickableHook;
17+
use Illuminate\Database\Eloquent\Model;
18+
19+
use Config;
20+
21+
class Bbcode {
22+
private function __construct()
23+
{
24+
25+
}
26+
27+
public static function decodaWithDefaults($data)
28+
{
29+
$code = new Decoda($data);
30+
$code->defaults();
31+
$code->removeHook('Censor');
32+
$code->removeHook('Clickable');
33+
$code->addHook(new ClickableHook());
34+
$code->setXhtml(false);
35+
$code->setStrict(false);
36+
$code->setLineBreaks(true);
37+
return $code;
38+
}
39+
40+
public static function parse($data)
41+
{
42+
return self::decodaWithDefaults($data)->parse();
43+
}
44+
}

app/Page.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
namespace App;
1414

1515
use Illuminate\Database\Eloquent\Model;
16-
use Decoda\Decoda;
16+
use App\Helpers\Bbcode;
1717

1818
/**
1919
* Model responsible for managing pages (as on Wordpress)
@@ -28,12 +28,6 @@ class Page extends Model
2828
*/
2929
public function getContentHtml()
3030
{
31-
$code = new Decoda($this->content);
32-
$code->defaults();
33-
$code->removeHook('Censor');
34-
$code->setXhtml(false);
35-
$code->setStrict(false);
36-
$code->setLineBreaks(true);
37-
return $code->parse();
31+
return Bbcode::parse($this->content);
3832
}
3933
}

app/Post.php

+2-11
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212

1313
namespace App;
1414

15-
use Decoda\Decoda;
1615
use Illuminate\Database\Eloquent\Model;
17-
use App\Hook\ClickableHook;
16+
use App\Helpers\Bbcode;
1817

1918
/**
2019
* Post new topic Reply to topic
@@ -67,15 +66,7 @@ public function likes()
6766
*/
6867
public function getContentHtml()
6968
{
70-
$code = new Decoda($this->content);
71-
$code->defaults();
72-
$code->removeHook('Censor');
73-
$code->removeHook('Clickable');
74-
$code->addHook(new ClickableHook());
75-
$code->setXhtml(false);
76-
$code->setStrict(false);
77-
$code->setLineBreaks(true);
78-
return $code->parse();
69+
return Bbcode::parse($this->content);
7970
}
8071

8172
/**

app/PrivateMessage.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Illuminate\Database\Eloquent\Model;
1616
use App\User;
1717
use Carbon\Carbon;
18-
use Decoda\Decoda;
18+
use App\Helpers\Bbcode;
1919

2020
class PrivateMessage extends Model
2121
{
@@ -47,12 +47,6 @@ public function receiver()
4747
*/
4848
public function getMessageHtml()
4949
{
50-
$code = new Decoda($this->message);
51-
$code->defaults();
52-
$code->removeHook('Censor');
53-
$code->setXhtml(false);
54-
$code->setStrict(false);
55-
$code->setLineBreaks(true);
56-
return $code->parse();
50+
return Bbcode::parse($this->message);
5751
}
5852
}

app/Requests.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
namespace App;
1414

1515
use Illuminate\Database\Eloquent\Model;
16-
use Decoda\Decoda;
16+
use App\Helpers\Bbcode;
1717

1818
/**
1919
* Torrent Requests
@@ -142,12 +142,6 @@ public function requestBounty()
142142
*/
143143
public function getDescriptionHtml()
144144
{
145-
$code = new Decoda($this->description);
146-
$code->defaults();
147-
$code->removeHook('Censor');
148-
$code->setXhtml(false);
149-
$code->setStrict(false);
150-
$code->setLineBreaks(true);
151-
return $code->parse();
145+
return Bbcode::parse($this->description);
152146
}
153147
}

app/Shoutbox.php

+2-10
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
use Illuminate\Database\Eloquent\Model;
1616
use Decoda\Decoda;
17-
use App\Hook\ClickableHook;
17+
use App\Helpers\Bbcode;
1818

1919
class Shoutbox extends Model
2020
{
@@ -39,14 +39,6 @@ public function poster()
3939
*/
4040
public static function getMessageHtml($message)
4141
{
42-
$code = new Decoda($message);
43-
$code->defaults();
44-
$code->removeHook('Censor');
45-
$code->removeHook('Clickable');
46-
$code->addHook(new ClickableHook());
47-
$code->setXhtml(false);
48-
$code->setStrict(false);
49-
$code->setLineBreaks(true);
50-
return $code->parse();
42+
return Bbcode::parse($message);
5143
}
5244
}

app/Torrent.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212

1313
namespace App;
1414

15-
use Decoda\Decoda;
1615
use Illuminate\Database\Eloquent\Model;
1716
use Hootlex\Moderation\Moderatable;
1817
use Kyslik\ColumnSortable\Sortable;
1918

2019
use App\Helpers\MediaInfo;
2120
use App\Helpers\StringHelper;
21+
use App\Helpers\Bbcode;
2222

2323
/**
2424
* Torrent model
@@ -151,13 +151,7 @@ public function moderated()
151151
*/
152152
public function getDescriptionHtml()
153153
{
154-
$code = new Decoda($this->description);
155-
$code->defaults();
156-
$code->removeHook('Censor');
157-
$code->setXhtml(false);
158-
$code->setStrict(false);
159-
$code->setLineBreaks(true);
160-
return $code->parse();
154+
return Bbcode::parse($this->description);
161155
}
162156

163157
/**

app/User.php

+3-15
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use App\Peer;
1818
use App\History;
1919

20-
use Decoda\Decoda;
2120
use Cache;
2221

2322
use Gstt\Achievements\Achiever;
@@ -27,6 +26,7 @@
2726
use function theodorejb\polycast\to_int;
2827

2928
use App\Helpers\StringHelper;
29+
use App\Helpers\Bbcode;
3030

3131
/**
3232
* User-Related Template
@@ -428,13 +428,7 @@ public function untilRatio($ratio)
428428
*/
429429
public function getSignature()
430430
{
431-
$code = new Decoda($this->signature);
432-
$code->defaults();
433-
$code->removeHook('Censor');
434-
$code->setXhtml(false);
435-
$code->setStrict(false);
436-
$code->setLineBreaks(true);
437-
return $code->parse();
431+
return Bbcode::parse($this->signature);
438432
}
439433

440434
/**
@@ -443,13 +437,7 @@ public function getSignature()
443437
*/
444438
public function getAboutHtml()
445439
{
446-
$code = new Decoda($this->about);
447-
$code->defaults();
448-
$code->removeHook('Censor');
449-
$code->setXhtml(false);
450-
$code->setStrict(false);
451-
$code->setLineBreaks(true);
452-
return $code->parse();
440+
return Bbcode::parse($this->about);
453441
}
454442

455443
/**

0 commit comments

Comments
 (0)