/
monitorcontributions.php
109 lines (95 loc) · 3.12 KB
/
monitorcontributions.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/**
* @package MonitorContributions
* @subpackage content
*
* @copyright Copyright (C) 2015 Constantin Romankiewicz.
* @license Apache License 2.0; see LICENSE
*/
defined('_JEXEC') or die;
/**
* Plugin to show user contributions (issues, comments) in their profiles.
*
* @author Constantin Romankiewicz <constantin@zweiiconkram.de>
* @since 1.0
*/
class PlgContentMonitorContributions extends JPlugin
{
/**
* Load the language file on instantiation.
*
* @var boolean
*
* @since 1.0
*/
protected $autoloadLanguage = true;
/**
* Database object to use in the plugin.
*
* @var JDatabaseDriver
*
* @since 1.0
*/
protected $db;
/**
* Event called after display of content.
*
* @param string $context The context of the content being passed to the plugin.
* @param mixed &$item The item displayed.
* @param mixed $params Additional parameters.
* @param integer $page Optional page number.
*
* @return string Returned value from this event will be displayed after the content of the item.
*/
public function onContentAfterDisplay($context, &$item, $params, $page = 0)
{
$allowed_contexts = array('com_contact.contact');
if (!in_array($context, $allowed_contexts))
{
return null;
}
// Check if the component is installed and enabled.
if (!JComponentHelper::isEnabled('com_monitor'))
{
return null;
}
JLoader::register('MonitorHelper', JPATH_ROOT . '/administrator/components/com_monitor/helper/helper.php');
JLoader::register('MonitorModelAbstract', JPATH_ROOT . '/administrator/components/com_monitor/model/abstract.php');
JLoader::register('MonitorModelComment', JPATH_ROOT . '/administrator/components/com_monitor/model/comment.php');
JLoader::register('MonitorModelIssue', JPATH_ROOT . '/administrator/components/com_monitor/model/issue.php');
$modelIssue = new MonitorModelIssue(null, false);
$modelComment = new MonitorModelComment(null, false);
// Load language files from the component.
$lang = JFactory::getLanguage();
$lang->load('com_monitor', JPATH_SITE . '/components/com_monitor');
$filters = array(
'author' => $item->user_id,
);
$listIssues = array(
'fullordering' => 'i.created DESC',
'limit' => $this->params->get('limit_issues', 10),
);
$listComments = array(
'fullordering' => 'c.created DESC',
'limit' => $this->params->get('limit_comments', 10),
);
$comments = $modelComment->getComments($filters, $listComments);
// Process the content plugins on comments.
$dispatcher = JEventDispatcher::getInstance();
JPluginHelper::importPlugin('content');
if ($comments)
{
foreach ($comments as $comment)
{
$dispatcher->trigger('onContentPrepare', array('plg_monitorcontributions.comment', &$comment, &$this->params, 0));
}
}
$displayData = array(
'item' => $item,
);
$displayData['issues'] = $modelIssue->getIssues($filters, $listIssues);
$displayData['comments'] = $comments;
$displayData['params'] = $this->params->merge(JComponentHelper::getParams('com_monitor'));
return JLayoutHelper::render('contributions', $displayData, __DIR__ . '/layouts');
}
}