forked from Kunena/Kunena-Forum
/
activity.php
153 lines (130 loc) · 5.49 KB
/
activity.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
/**
* Kunena Plugin
* @package Kunena.Plugins
* @subpackage AlphaUserPoints
*
* @copyright (C) 2008 - 2013 Kunena Team. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @link http://www.kunena.org
**/
defined ( '_JEXEC' ) or die ();
jimport('joomla.utilities.string');
class KunenaActivityAlphaUserPoints extends KunenaActivity {
protected $params = null;
public function __construct($params) {
$this->params = $params;
}
protected function _getAUPversion() {
return AlphaUserPointsHelper::getAupVersion();
}
protected function _buildKeyreference( $plugin_function, $spc='' ) {
return AlphaUserPointsHelper::buildKeyreference($plugin_function, $spc);
}
public function onAfterPost($message) {
// Check for permisions of the current category - activity only if public or registered
if ( $this->_checkPermissions($message) ) {
$datareference = '<a rel="nofollow" href="' . KunenaRoute::_($message->getPermaUrl()) . '">' . $message->subject . '</a>';
$referreid = AlphaUserPointsHelper::getReferreid( $message->userid );
if (JString::strlen($message->message) > $this->params->get('activity_points_limit', 0)) {
if ( $this->_checkRuleEnabled( 'plgaup_kunena_topic_create' ) ) {
$keyreference = $this->_buildKeyreference( 'plgaup_kunena_topic_create', $message->id ) ;
AlphaUserPointsHelper::newpoints ( 'plgaup_kunena_topic_create', $referreid, $keyreference, $datareference );
}
}
}
return true;
}
public function onAfterReply($message) {
// Check for permisions of the current category - activity only if public or registered
if ( $this->_checkPermissions($message) ) {
$datareference = '<a rel="nofollow" href="' . KunenaRoute::_($message->getPermaUrl()) . '">' . $message->subject . '</a>';
$referreid = AlphaUserPointsHelper::getReferreid( $message->userid );
if (JString::strlen($message->message) > $this->params->get('activity_points_limit', 0)) {
if ( $this->_checkRuleEnabled( 'plgaup_kunena_topic_reply' ) ) {
$keyreference = $this->_buildKeyreference( 'plgaup_kunena_topic_reply', $message->id ) ;
AlphaUserPointsHelper::newpoints ( 'plgaup_kunena_topic_reply', $referreid, $keyreference, $datareference );
}
}
}
}
public function onAfterDelete($message) {
// Check for permisions of the current category - activity only if public or registered
if ( $this->_checkPermissions($message) ) {
$aupid = AlphaUserPointsHelper::getAnyUserReferreID( $message->userid );
if ( $aupid ) {
if ( $this->_checkRuleEnabled( 'plgaup_kunena_message_delete' ) ) {
AlphaUserPointsHelper::newpoints( 'plgaup_kunena_message_delete', $aupid);
}
}
}
}
public function onAfterThankyou($target, $actor, $message) {
$infoTargetUser = (JText::_ ( 'COM_KUNENA_THANKYOU_GOT' ).': ' . KunenaFactory::getUser($target)->username );
$infoRootUser = ( JText::_ ( 'COM_KUNENA_THANKYOU_SAID' ).': ' . KunenaFactory::getUser($actor)->username );
if ( $this->_checkPermissions($message) ) {
$auptarget = AlphaUserPointsHelper::getAnyUserReferreID( $actor );
$aupactor = AlphaUserPointsHelper::getAnyUserReferreID( $target );
$ruleName = 'plgaup_kunena_message_thankyou';
$usertargetpoints = intval($this->_getPointsOnThankyou($ruleName));
if ( $usertargetpoints && $this->_checkRuleEnabled($ruleName) ) {
// for target user
if ($auptarget) AlphaUserPointsHelper::newpoints($ruleName , $auptarget, '', $infoTargetUser, $usertargetpoints);
// for who has gived the thank you
if ($aupactor) AlphaUserPointsHelper::newpoints($ruleName , $aupactor, '', $infoRootUser );
}
}
}
function escape($var) {
return htmlspecialchars ( $var, ENT_COMPAT, 'UTF-8' );
}
public function getUserMedals($userid) {
if ($userid == 0)
return false;
if (! defined ( "_AUP_MEDALS_LIVE_PATH" )) {
define ( '_AUP_MEDALS_LIVE_PATH', JUri::root(true) . '/components/com_alphauserpoints/assets/images/awards/icons/' );
}
$aupmedals = AlphaUserPointsHelper::getUserMedals ( '', $userid );
$medals = array ();
foreach ( $aupmedals as $medal ) {
$medals [] = '<img src="' . _AUP_MEDALS_LIVE_PATH . $this->escape ( $medal->icon ) . '" alt="' . $this->escape ( $medal->rank ) . '" title="' . $this->escape ( $medal->rank ) . '" />';
}
return $medals;
}
public function getUserPoints($userid) {
if ($userid == 0)
return false;
$_db = JFactory::getDBO ();
$_db->setQuery ( "SELECT points FROM #__alpha_userpoints WHERE `userid`='" . ( int ) $userid . "'" );
$userpoints = $_db->loadResult ();
KunenaError::checkDatabaseError ();
return $userpoints;
}
private function _checkPermissions($message) {
$category = $message->getCategory();
$accesstype = $category->accesstype;
if ($accesstype != 'joomla.group' && $accesstype != 'joomla.level') {
return false;
}
// FIXME: Joomla 2.5 can mix up groups and access levels
if ($accesstype == 'joomla.level' && $category->access <= 2) {
return true;
} elseif ($category->pub_access == 1 || $category->pub_access == 2) {
return true;
} elseif ($category->admin_access == 1 || $category->admin_access == 2) {
return true;
}
return false;
}
private function _checkRuleEnabled($ruleName) {
$ruleEnabled = AlphaUserPointsHelper::checkRuleEnabled($ruleName);
return !empty($ruleEnabled[0]->published);
}
private function _getPointsOnThankyou($ruleName) {
$ruleEnabled = AlphaUserPointsHelper::checkRuleEnabled($ruleName);
if (!empty($ruleEnabled[0]->published)) {
return $ruleEnabled[0]->points2;
}
return null;
}
}