1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Noair\Event; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* A default Noair Observer |
7
|
|
|
* |
8
|
|
|
* This is the default Noair Observer, which other plugins/listeners |
9
|
|
|
* will override its functionality |
10
|
|
|
* |
11
|
|
|
* @author Garrett Whitehorn |
12
|
|
|
* @author David Tkachuk |
13
|
|
|
* @package Noair |
14
|
|
|
* @subpackage NoairExample |
15
|
|
|
* @version 1.0 |
16
|
|
|
*/ |
17
|
|
|
class Formatter extends Noair\Observer |
18
|
|
|
{ |
19
|
|
|
public function subscribe() { |
20
|
|
|
// This is just here for an example of explicitly-defined handlers |
21
|
|
|
$this->handlers = [ |
22
|
|
|
'formatUsername' => [[$this, 'formatUsername']], |
23
|
|
|
'formatGroup' => [[$this, 'formatGroup']], |
24
|
|
|
'formatDate' => [[$this, 'formatDate']], |
25
|
|
|
'formatMessage' => [[$this, 'formatMessage']], |
26
|
|
|
]; |
27
|
|
|
|
28
|
|
|
return parent::subscribe(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function formatUsername(Event $event) { |
32
|
|
|
return $event->data; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function formatGroup(Event $event) { |
36
|
|
|
return $event->data; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function formatMessage(Event $event) { |
40
|
|
|
return nl2br($event->data); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function formatDate(Event $event) { |
|
|
|
|
44
|
|
|
// return date('F j, Y h:i:s A', $event->data); |
|
|
|
|
45
|
|
|
return ''; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function onCreatePost(Event $event) { |
49
|
|
|
$result = '<div style="padding: 9px 16px;border:1px solid #EEE;margin-bottom:16px;">' |
50
|
|
|
.'<strong>Posted by</strong> ' |
51
|
|
|
.$this->mediator->publish(new Event('formatUsername', $event->data['username'], $this)) |
52
|
|
|
.' (' |
53
|
|
|
.$this->mediator->publish(new Event('formatGroup', $event->data['group'], $this)) |
54
|
|
|
.')<br /><strong>Posted Date</strong> ' |
55
|
|
|
.$this->mediator->publish(new Event('formatDate', $event->data['date'], $this)) |
56
|
|
|
.'<br />' |
57
|
|
|
.$this->mediator->publish(new Event('formatMessage', $event->data['message'], $this)) |
58
|
|
|
.'</div>'; |
59
|
|
|
return $result; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.