/
ThreadAuthorReplyFormatter.php
75 lines (67 loc) · 1.77 KB
/
ThreadAuthorReplyFormatter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/**
* Alert formatter for private thread author reply alerts.
*/
class MybbStuff_MyAlerts_Formatter_ThreadAuthorReplyFormatter
extends MybbStuff_MyAlerts_Formatter_AbstractFormatter
{
/**
* @var postParser $parser
*/
private $parser;
/**
* Format an alert into it's output string to be used in both the main
* alerts listing page and the popup.
*
* @param MybbStuff_MyAlerts_Entity_Alert $alert The alert to format.
*
* @return string The formatted alert string.
*/
public function formatAlert(
MybbStuff_MyAlerts_Entity_Alert $alert,
array $outputAlert
) {
$alertContent = $alert->getExtraDetails();
$threadLink = $this->buildShowLink($alert);
return $this->lang->sprintf(
$this->lang->myalerts_post_threadauthor,
$outputAlert['from_user'],
htmlspecialchars_uni(
$this->parser->parse_badwords($alertContent['t_subject'])
)
);
}
/**
* Init function called before running formatAlert(). Used to load language
* files and initialize other required resources.
*
* @return void
*/
public function init()
{
if (!$this->lang->myalerts) {
$this->lang->load('myalerts');
}
require_once MYBB_ROOT . 'inc/class_parser.php';
$this->parser = new postParser;
}
/**
* Build a link to an alert's content so that the system can redirect to
* it.
*
* @param MybbStuff_MyAlerts_Entity_Alert $alert The alert to build the
* link for.
*
* @return string The built alert, preferably an absolute link.
*/
public function buildShowLink(MybbStuff_MyAlerts_Entity_Alert $alert)
{
$alertContent = $alert->getExtraDetails();
$threadLink = $this->mybb->settings['bburl'] . '/' . get_thread_link(
(int) $alertContent['tid'],
0,
'newpost'
);
return $threadLink;
}
}