2013-10-24 13:14:52 -05:00
|
|
|
<?php if(!defined('APPLICATION')) exit();
|
2013-10-25 17:05:01 -05:00
|
|
|
|
2013-10-24 13:14:52 -05:00
|
|
|
/**
|
|
|
|
* A special function that is automatically run upon enabling your application.
|
|
|
|
*
|
|
|
|
* Remember to rename this to FooHooks, where 'Foo' is you app's short name.
|
|
|
|
*/
|
|
|
|
class YagaHooks implements Gdn_IPlugin {
|
|
|
|
|
2013-11-12 09:11:32 -06:00
|
|
|
/**
|
|
|
|
* Add the settings page links
|
|
|
|
*
|
|
|
|
* @param Object $Sender
|
|
|
|
*/
|
|
|
|
public function Base_GetAppSettingsMenuItems_Handler($Sender) {
|
|
|
|
$Menu = $Sender->EventArguments['SideMenu'];
|
|
|
|
$Section = 'Gamification';
|
|
|
|
$Attrs = array('class' => $Section);
|
|
|
|
$Menu->AddItem($Section, $Section, FALSE, $Attrs);
|
2013-12-10 15:29:07 -06:00
|
|
|
$Menu->AddLink($Section, T('Settings'), 'yaga/settings', 'Garden.Settings.Manage');
|
2013-11-12 09:11:32 -06:00
|
|
|
if(C('Yaga.Reactions.Enabled')) {
|
2013-12-04 14:09:26 -06:00
|
|
|
$Menu->AddLink($Section, T('Yaga.Reactions'), 'action/settings', 'Yaga.Reactions.Manage');
|
2013-11-12 09:11:32 -06:00
|
|
|
}
|
|
|
|
if(C('Yaga.Badges.Enabled')) {
|
2013-12-04 14:09:26 -06:00
|
|
|
$Menu->AddLink($Section, T('Yaga.Badges'), 'badge/settings', 'Yaga.Badges.Manage');
|
2013-11-12 09:11:32 -06:00
|
|
|
}
|
|
|
|
if(C('Yaga.Ranks.Enabled')) {
|
2013-12-04 14:09:26 -06:00
|
|
|
$Menu->AddLink($Section, T('Yaga.Ranks'), 'rank/settings', 'Yaga.Ranks.Manage');
|
2013-11-12 09:11:32 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 17:05:01 -05:00
|
|
|
/**
|
|
|
|
* Display the reaction counts on the profile page
|
2013-11-12 09:11:32 -06:00
|
|
|
* @param object $Sender
|
2013-10-25 17:05:01 -05:00
|
|
|
*/
|
|
|
|
public function ProfileController_AfterUserInfo_Handler($Sender) {
|
|
|
|
$User = $Sender->User;
|
2013-11-19 15:15:42 -06:00
|
|
|
$Method = $Sender->RequestMethod;
|
|
|
|
if($Method == 'reactions') {
|
|
|
|
$ActionID = $Sender->RequestArgs[2];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$ActionID = -1;
|
|
|
|
}
|
2013-11-18 15:21:35 -06:00
|
|
|
echo '<div class="Yaga ReactionsWrap">';
|
|
|
|
echo Wrap(T('Yaga.Reactions', 'Reactions'), 'h2', array('class' => 'H'));
|
2013-11-11 14:45:31 -06:00
|
|
|
|
2013-10-25 17:05:01 -05:00
|
|
|
// insert the reaction totals in the profile
|
2013-12-03 17:17:16 -06:00
|
|
|
$ReactionModel = Yaga::ReactionModel();
|
2013-12-11 17:36:32 -06:00
|
|
|
$Actions = Yaga::ActionModel()->Get();
|
2013-10-25 17:05:01 -05:00
|
|
|
$String = '';
|
|
|
|
foreach($Actions as $Action) {
|
2013-11-19 15:15:42 -06:00
|
|
|
$Selected = ($ActionID == $Action->ActionID) ? ' Selected' : '';
|
2013-12-03 17:17:16 -06:00
|
|
|
$Count = $ReactionModel->GetUserReactionCount($User->UserID, $Action->ActionID);
|
2013-11-18 15:21:35 -06:00
|
|
|
$TempString = Wrap(Wrap(Gdn_Format::BigNumber($Count), 'span', array('title' => $Count)), 'span', array('class' => 'Yaga_ReactionCount CountTotal'));
|
|
|
|
$TempString .= Wrap($Action->Name, 'span', array('class' => 'Yaga_ReactionName CountLabel'));
|
2013-10-25 17:05:01 -05:00
|
|
|
|
2013-11-19 15:15:42 -06:00
|
|
|
$String .= Wrap(Wrap(Anchor($TempString, '/profile/reactions/' . $User->UserID . '/' . Gdn_Format::Url($User->Name) . '/' . $Action->ActionID, array('class' => 'Yaga_Reaction TextColor', 'title' => $Action->Description)), 'span', array('class' => 'CountItem' . $Selected)), 'span', array('class' => 'CountItemWrap'));
|
2013-10-25 17:05:01 -05:00
|
|
|
}
|
2013-11-11 14:45:31 -06:00
|
|
|
|
2013-10-25 17:05:01 -05:00
|
|
|
echo Wrap($String, 'div', array('class' => 'DataCounts'));
|
|
|
|
}
|
2013-12-09 17:12:22 -06:00
|
|
|
|
2013-11-22 16:08:30 -06:00
|
|
|
/**
|
|
|
|
* Add the badge count into the user info module
|
2013-12-09 17:12:22 -06:00
|
|
|
*
|
2013-11-22 16:08:30 -06:00
|
|
|
* @param UserInfoModule $Sender
|
|
|
|
*/
|
|
|
|
public function UserInfoModule_OnBasicInfo_Handler($Sender) {
|
2013-12-09 17:12:22 -06:00
|
|
|
echo '<dt class="Badges">' . T('Yaga.Badges', 'Badges') . '</dt> ';
|
2013-12-10 16:50:10 -06:00
|
|
|
echo '<dd class="Badges">' . $Sender->User->CountBadges . '</dd>';
|
2013-11-22 16:08:30 -06:00
|
|
|
}
|
2013-11-11 14:45:31 -06:00
|
|
|
|
2013-11-18 15:21:35 -06:00
|
|
|
/**
|
2013-12-10 15:29:07 -06:00
|
|
|
* This method shows the latest discussions/comments a user has posted that
|
|
|
|
* received the specified action
|
|
|
|
*
|
|
|
|
* @param ProfileController $Sender
|
|
|
|
* @param int $UserReference
|
|
|
|
* @param string $Username
|
|
|
|
* @param int $ActionID
|
|
|
|
* @param int $Page
|
2013-11-18 15:21:35 -06:00
|
|
|
*/
|
2013-12-10 15:29:07 -06:00
|
|
|
public function ProfileController_Reactions_Create($Sender, $UserReference = '', $Username = '', $ActionID = '', $Page = '') {
|
2013-11-18 15:21:35 -06:00
|
|
|
$Expiry = 60;
|
2013-12-09 17:12:22 -06:00
|
|
|
|
2013-11-18 15:21:35 -06:00
|
|
|
$Sender->EditMode(FALSE);
|
|
|
|
|
|
|
|
// Tell the ProfileController what tab to load
|
2013-12-10 15:29:07 -06:00
|
|
|
$Sender->GetUserInfo($UserReference, $Username);
|
2013-12-04 14:09:26 -06:00
|
|
|
$Sender->_SetBreadcrumbs(T('Yaga.Reactions'), UserUrl($Sender->User, '', 'reactions'));
|
|
|
|
$Sender->SetTabView(T('Yaga.Reactions'), 'reactions', 'profile', 'Yaga');
|
2013-12-09 17:12:22 -06:00
|
|
|
|
2013-11-18 15:21:35 -06:00
|
|
|
$Sender->AddJsFile('jquery.expander.js');
|
|
|
|
$Sender->AddJsFile('reactions.js', 'yaga');
|
|
|
|
$Sender->AddDefinition('ExpandText', T('(more)'));
|
|
|
|
$Sender->AddDefinition('CollapseText', T('(less)'));
|
2013-12-09 17:12:22 -06:00
|
|
|
|
2013-11-18 15:21:35 -06:00
|
|
|
$PageSize = Gdn::Config('Vanilla.Discussions.PerPage', 30);
|
|
|
|
list($Offset, $Limit) = OffsetLimit($Page, $PageSize);
|
|
|
|
|
|
|
|
// Check cache
|
|
|
|
$CacheKey = "yaga.profile.reactions.{$ActionID}";
|
|
|
|
$Content = Gdn::Cache()->Get($CacheKey);
|
2013-12-09 17:12:22 -06:00
|
|
|
|
|
|
|
if($Content == Gdn_Cache::CACHEOP_FAILURE) {
|
|
|
|
|
|
|
|
// Get matching Discussions
|
|
|
|
$Type = 'discussion';
|
|
|
|
$Discussions = Gdn::SQL()->Select('d.*')
|
|
|
|
->From('Discussion d')
|
|
|
|
->Join('Reaction r', 'd.DiscussionID = r.ParentID')
|
|
|
|
//->Where('r.ParentAuthorID', $UserReference)
|
|
|
|
->Where('d.InsertUserID', $UserReference)
|
|
|
|
->Where('r.ActionID', $ActionID)
|
|
|
|
// ->Where('r.ParentType', $Type)
|
|
|
|
->OrderBy('r.DateInserted', 'DESC')
|
|
|
|
->Limit($Limit)
|
|
|
|
->Get()->Result(DATASET_TYPE_ARRAY);
|
|
|
|
|
|
|
|
// Get matching Comments
|
|
|
|
$Comments = Gdn::SQL()->Select('c.*')
|
|
|
|
->From('Comment c')
|
|
|
|
->Join('Reaction r', 'c.CommentID = r.ParentID')
|
|
|
|
//->Where('r.ParentAuthorID', 'c.InsertUserID')
|
|
|
|
// ->Where('r.ParentType', '\'comment\'')
|
|
|
|
->Where('c.InsertUserID', $UserReference)
|
|
|
|
->Where('r.ActionID', $ActionID)
|
|
|
|
// ->Where('r.ParentType', $Type)
|
|
|
|
->OrderBy('r.DateInserted', 'DESC')
|
|
|
|
->Limit($Limit)
|
|
|
|
->Get()->Result(DATASET_TYPE_ARRAY);
|
|
|
|
|
|
|
|
$this->JoinCategory($Comments);
|
|
|
|
|
|
|
|
// Interleave
|
|
|
|
$Content = $this->Union('DateInserted', array(
|
|
|
|
'Discussion' => $Discussions,
|
|
|
|
'Comment' => $Comments
|
|
|
|
));
|
|
|
|
$this->Prepare($Content);
|
|
|
|
|
|
|
|
// Add result to cache
|
|
|
|
Gdn::Cache()->Store($CacheKey, $Content, array(
|
|
|
|
Gdn_Cache::FEATURE_EXPIRY => $Expiry
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->Security($Content);
|
|
|
|
$this->Condense($Content, $Limit);
|
2013-11-18 15:21:35 -06:00
|
|
|
|
|
|
|
// Deliver JSON data if necessary
|
2013-12-09 17:12:22 -06:00
|
|
|
if($Sender->DeliveryType() != DELIVERY_TYPE_ALL && $Offset > 0) {
|
|
|
|
$Sender->SetJson('LessRow', $Sender->Pager->ToString('less'));
|
|
|
|
$Sender->SetJson('MoreRow', $Sender->Pager->ToString('more'));
|
|
|
|
$Sender->View = 'reactions';
|
2013-11-18 15:21:35 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
$Sender->SetData('Content', $Content);
|
2013-12-09 17:12:22 -06:00
|
|
|
|
2013-11-18 15:21:35 -06:00
|
|
|
// Set the HandlerType back to normal on the profilecontroller so that it fetches it's own views
|
|
|
|
$Sender->HandlerType = HANDLER_TYPE_NORMAL;
|
|
|
|
|
|
|
|
// Do not show discussion options
|
|
|
|
$Sender->ShowOptions = FALSE;
|
|
|
|
|
2013-12-09 17:12:22 -06:00
|
|
|
if($Sender->Head) {
|
|
|
|
$Sender->Head->AddTag('meta', array('name' => 'robots', 'content' => 'noindex,noarchive'));
|
2013-11-18 15:21:35 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Render the ProfileController
|
|
|
|
$Sender->Render();
|
|
|
|
}
|
2013-12-09 17:12:22 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Attach CategoryID to Comments
|
2013-12-10 15:29:07 -06:00
|
|
|
*
|
2013-12-09 17:12:22 -06:00
|
|
|
* @param array $Comments
|
|
|
|
*/
|
|
|
|
protected function JoinCategory(&$Comments) {
|
|
|
|
$DiscussionIDs = array();
|
|
|
|
|
|
|
|
foreach($Comments as &$Comment) {
|
|
|
|
$DiscussionIDs[$Comment['DiscussionID']] = TRUE;
|
|
|
|
}
|
|
|
|
$DiscussionIDs = array_keys($DiscussionIDs);
|
|
|
|
|
|
|
|
$Discussions = Gdn::SQL()->Select('d.*')
|
|
|
|
->From('Discussion d')
|
|
|
|
->WhereIn('DiscussionID', $DiscussionIDs)
|
|
|
|
->Get()->Result(DATASET_TYPE_ARRAY);
|
|
|
|
|
|
|
|
$DiscussionsByID = array();
|
|
|
|
foreach($Discussions as $Discussion) {
|
|
|
|
$DiscussionsByID[$Discussion['DiscussionID']] = $Discussion;
|
|
|
|
}
|
|
|
|
unset(${$Discussions});
|
|
|
|
|
|
|
|
foreach($Comments as &$Comment) {
|
|
|
|
$Comment['Discussion'] = $DiscussionsByID[$Comment['DiscussionID']];
|
|
|
|
$Comment['CategoryID'] = GetValueR('Discussion.CategoryID', $Comment);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interleave two or more result arrays by a common field
|
2013-12-10 15:29:07 -06:00
|
|
|
*
|
2013-12-09 17:12:22 -06:00
|
|
|
* @param string $Field
|
|
|
|
* @param array $Sections Array of result arrays
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function Union($Field, $Sections) {
|
|
|
|
if(!is_array($Sections))
|
|
|
|
return;
|
|
|
|
|
|
|
|
$Interleaved = array();
|
|
|
|
foreach($Sections as $SectionType => $Section) {
|
|
|
|
if(!is_array($Section))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
foreach($Section as $Item) {
|
|
|
|
$ItemField = GetValue($Field, $Item);
|
|
|
|
$Interleaved[$ItemField] = array_merge($Item, array('ItemType' => $SectionType));
|
|
|
|
|
|
|
|
ksort($Interleaved);
|
2013-11-18 15:21:35 -06:00
|
|
|
}
|
2013-12-09 17:12:22 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
$Interleaved = array_reverse($Interleaved);
|
|
|
|
return $Interleaved;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pre-process content into a uniform format for output
|
2013-12-10 15:29:07 -06:00
|
|
|
*
|
2013-12-09 17:12:22 -06:00
|
|
|
* @param Array $Content By reference
|
|
|
|
*/
|
|
|
|
protected function Prepare(&$Content) {
|
|
|
|
|
|
|
|
foreach($Content as &$ContentItem) {
|
|
|
|
$ContentType = GetValue('ItemType', $ContentItem);
|
|
|
|
|
|
|
|
$Replacement = array();
|
|
|
|
$Fields = array('DiscussionID', 'CategoryID', 'DateInserted', 'DateUpdated', 'InsertUserID', 'Body', 'Format', 'ItemType');
|
|
|
|
|
|
|
|
switch(strtolower($ContentType)) {
|
|
|
|
case 'comment':
|
|
|
|
$Fields = array_merge($Fields, array('CommentID'));
|
|
|
|
|
|
|
|
// Comment specific
|
|
|
|
$Replacement['Name'] = GetValueR('Discussion.Name', $ContentItem);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'discussion':
|
|
|
|
$Fields = array_merge($Fields, array('Name', 'Type'));
|
|
|
|
break;
|
2013-11-18 15:21:35 -06:00
|
|
|
}
|
2013-12-09 17:12:22 -06:00
|
|
|
|
|
|
|
$Fields = array_fill_keys($Fields, TRUE);
|
|
|
|
$Common = array_intersect_key($ContentItem, $Fields);
|
|
|
|
$Replacement = array_merge($Replacement, $Common);
|
|
|
|
$ContentItem = $Replacement;
|
|
|
|
|
|
|
|
// Attach User
|
|
|
|
$UserID = GetValue('InsertUserID', $ContentItem);
|
|
|
|
$User = Gdn::UserModel()->GetID($UserID);
|
|
|
|
$ContentItem['Author'] = $User;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Strip out content that this user is not allowed to see
|
2013-12-10 15:29:07 -06:00
|
|
|
*
|
2013-12-09 17:12:22 -06:00
|
|
|
* @param array $Content Content array, by reference
|
|
|
|
*/
|
|
|
|
protected function Security(&$Content) {
|
|
|
|
if(!is_array($Content))
|
|
|
|
return;
|
|
|
|
$Content = array_filter($Content, array($this, 'SecurityFilter'));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function SecurityFilter($ContentItem) {
|
|
|
|
$CategoryID = GetValue('CategoryID', $ContentItem, NULL);
|
|
|
|
if(is_null($CategoryID) || $CategoryID === FALSE)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
$Category = CategoryModel::Categories($CategoryID);
|
|
|
|
$CanView = GetValue('PermsDiscussionsView', $Category);
|
|
|
|
if(!$CanView)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Condense an interleaved content list down to the required size
|
2013-12-10 15:29:07 -06:00
|
|
|
*
|
2013-12-09 17:12:22 -06:00
|
|
|
* @param array $Content
|
|
|
|
* @param array $Limit
|
|
|
|
*/
|
|
|
|
protected function Condense(&$Content, $Limit) {
|
|
|
|
$Content = array_slice($Content, 0, $Limit);
|
|
|
|
}
|
|
|
|
|
2013-12-09 17:27:50 -06:00
|
|
|
/**
|
|
|
|
* Check for promotions on received points.
|
|
|
|
*
|
|
|
|
* @param type $Sender
|
|
|
|
* @return type
|
|
|
|
*/
|
2013-12-09 17:12:22 -06:00
|
|
|
public function UserModel_GivePoints_Handler($Sender) {
|
2013-12-09 17:27:50 -06:00
|
|
|
// Don't check for promotions if we aren't using ranks
|
|
|
|
if(!C('Yaga.Ranks.Enabled')) {
|
|
|
|
return;
|
|
|
|
}
|
2013-12-09 17:12:22 -06:00
|
|
|
$UserID = $Sender->EventArguments['UserID'];
|
|
|
|
$UserModel = Gdn::UserModel();
|
|
|
|
$User = $UserModel->GetID($UserID);
|
2013-12-11 14:38:34 -06:00
|
|
|
|
|
|
|
// Don't try to promote if they are frozen
|
|
|
|
if(!$User->RankProgression) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-12-09 17:12:22 -06:00
|
|
|
$Points = $Sender->EventArguments['Points'];
|
|
|
|
$RankModel = Yaga::RankModel();
|
2013-12-11 13:48:06 -06:00
|
|
|
$Rank = $RankModel->GetByPoints($Points);
|
|
|
|
|
2013-12-09 17:12:22 -06:00
|
|
|
if($Rank && $Rank->RankID != $User->RankID) {
|
|
|
|
// Only promote automatically
|
2013-12-11 13:48:06 -06:00
|
|
|
$OldRank = $RankModel->GetByID($User->RankID);
|
2013-12-09 17:12:22 -06:00
|
|
|
if($OldRank->Level <= $Rank->Level) {
|
2013-12-11 13:48:06 -06:00
|
|
|
$RankModel->Set($Rank->RankID, $UserID, TRUE);
|
2013-11-18 15:21:35 -06:00
|
|
|
}
|
2013-12-09 17:12:22 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transparently inject the rank permissions a user has earned
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-11-12 09:11:32 -06:00
|
|
|
/**
|
|
|
|
* Add the badge and rank notification options
|
2013-12-09 17:12:22 -06:00
|
|
|
*
|
2013-11-12 09:11:32 -06:00
|
|
|
* @param object $Sender
|
|
|
|
*/
|
2013-11-11 16:30:16 -06:00
|
|
|
public function ProfileController_AfterPreferencesDefined_Handler($Sender) {
|
2013-11-12 09:11:32 -06:00
|
|
|
if(C('Yaga.Badges.Enabled')) {
|
2013-12-04 14:09:26 -06:00
|
|
|
$Sender->Preferences['Notifications']['Email.Badges'] = T('Yaga.Notifications.Badges');
|
|
|
|
$Sender->Preferences['Notifications']['Popup.Badges'] = T('Yaga.Notifications.Badges');
|
2013-11-12 09:11:32 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if(C('Yaga.Ranks.Enabled')) {
|
2013-12-04 14:09:26 -06:00
|
|
|
$Sender->Preferences['Notifications']['Email.Ranks'] = T('Yaga.Notifications.Ranks');
|
|
|
|
$Sender->Preferences['Notifications']['Popup.Ranks'] = T('Yaga.Notifications.Ranks');
|
2013-11-12 09:11:32 -06:00
|
|
|
}
|
2013-11-11 16:30:16 -06:00
|
|
|
}
|
2013-11-12 09:11:32 -06:00
|
|
|
|
2013-11-13 16:17:08 -06:00
|
|
|
/**
|
2013-12-09 17:12:22 -06:00
|
|
|
* Add the Award Badge and Promote options to the profile controller
|
2013-11-13 16:17:08 -06:00
|
|
|
*
|
|
|
|
* @param object $Sender
|
|
|
|
*/
|
|
|
|
public function ProfileController_BeforeProfileOptions_Handler($Sender) {
|
2013-12-03 17:17:16 -06:00
|
|
|
if(Gdn::Session()->IsValid()) {
|
2013-12-09 17:12:22 -06:00
|
|
|
if(C('Yaga.Badges.Enabled') && CheckPermission('Yaga.Badges.Add')) {
|
2013-12-03 17:17:16 -06:00
|
|
|
$Sender->EventArguments['ProfileOptions'][] = array(
|
2013-12-04 14:09:26 -06:00
|
|
|
'Text' => Sprite('SpRibbon') . ' ' . T('Yaga.Badge.Award'),
|
2013-12-03 17:17:16 -06:00
|
|
|
'Url' => '/badge/award/' . $Sender->User->UserID,
|
|
|
|
'CssClass' => 'Popup'
|
|
|
|
);
|
|
|
|
}
|
2013-12-09 17:12:22 -06:00
|
|
|
|
|
|
|
if(C('Yaga.Ranks.Enabled') && CheckPermission('Yaga.Ranks.Add')) {
|
2013-12-03 17:17:16 -06:00
|
|
|
$Sender->EventArguments['ProfileOptions'][] = array(
|
2013-12-04 14:09:26 -06:00
|
|
|
'Text' => Sprite('SpModeratorActivities') . ' ' . T('Yaga.Rank.Promote'),
|
2013-12-03 17:17:16 -06:00
|
|
|
'Url' => '/rank/promote/' . $Sender->User->UserID,
|
|
|
|
'CssClass' => 'Popup'
|
|
|
|
);
|
|
|
|
}
|
2013-11-13 16:17:08 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 17:05:01 -05:00
|
|
|
/**
|
|
|
|
* Display a record of reactions after the first post
|
2013-11-12 09:11:32 -06:00
|
|
|
*
|
|
|
|
* @param object $Sender
|
2013-10-25 17:05:01 -05:00
|
|
|
*/
|
|
|
|
public function DiscussionController_AfterDiscussionBody_Handler($Sender) {
|
2013-12-03 17:33:39 -06:00
|
|
|
if(!Gdn::Session()->CheckPermission('Yaga.Reactions.View') || !C('Yaga.Reactions.Enabled')) {
|
2013-11-20 16:37:31 -06:00
|
|
|
return;
|
|
|
|
}
|
2013-10-25 17:05:01 -05:00
|
|
|
$Type = 'discussion';
|
|
|
|
$ID = $Sender->DiscussionID;
|
2013-11-20 16:37:31 -06:00
|
|
|
RenderReactionRecord($ID, $Type);
|
2013-10-25 17:05:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a record of reactions after comments
|
2013-11-12 09:11:32 -06:00
|
|
|
* @param object $Sender
|
2013-10-25 17:05:01 -05:00
|
|
|
*/
|
|
|
|
public function DiscussionController_AfterCommentBody_Handler($Sender) {
|
2013-12-03 17:33:39 -06:00
|
|
|
if(!Gdn::Session()->CheckPermission('Yaga.Reactions.View') || !C('Yaga.Reactions.Enabled')) {
|
2013-10-25 17:05:01 -05:00
|
|
|
return;
|
|
|
|
}
|
2013-11-20 16:37:31 -06:00
|
|
|
$Type = 'comment';
|
|
|
|
$ID = $Sender->EventArguments['Comment']->CommentID;
|
|
|
|
RenderReactionRecord($ID, $Type);
|
2013-10-25 17:05:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-11-07 11:19:32 -06:00
|
|
|
* Add action list to discussion items
|
2013-11-12 09:11:32 -06:00
|
|
|
* @param object $Sender
|
2013-10-25 17:05:01 -05:00
|
|
|
*/
|
|
|
|
public function DiscussionController_AfterReactions_Handler($Sender) {
|
|
|
|
if(C('Yaga.Reactions.Enabled') == FALSE) {
|
|
|
|
return;
|
|
|
|
}
|
2013-12-09 17:12:22 -06:00
|
|
|
|
2013-10-25 17:05:01 -05:00
|
|
|
// check to see if allowed to add reactions
|
2013-11-15 23:14:32 -06:00
|
|
|
if(!Gdn::Session()->CheckPermission('Yaga.Reactions.Add')) {
|
2013-10-25 17:05:01 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Users shouldn't be able to react to their own content
|
|
|
|
$Type = $Sender->EventArguments['RecordType'];
|
|
|
|
$ID = $Sender->EventArguments['RecordID'];
|
|
|
|
|
2013-12-09 17:12:22 -06:00
|
|
|
if(array_key_exists('Author', $Sender->EventArguments)) {
|
|
|
|
$Author = $Sender->EventArguments['Author'];
|
|
|
|
$AuthorID = $Author->UserID;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$Discussion = $Sender->EventArguments['Discussion'];
|
|
|
|
$AuthorID = $Discussion->InsertUserID;
|
|
|
|
}
|
|
|
|
|
2013-10-25 17:05:01 -05:00
|
|
|
// Users shouldn't be able to react to their own content
|
2013-12-09 17:12:22 -06:00
|
|
|
if(Gdn::Session()->UserID != $AuthorID) {
|
2013-11-20 16:56:02 -06:00
|
|
|
RenderReactions($ID, $Type);
|
2013-10-25 17:05:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the action list to any activity items that can be commented on
|
2013-11-12 09:11:32 -06:00
|
|
|
*
|
|
|
|
* @param object $Sender
|
2013-10-25 17:05:01 -05:00
|
|
|
*/
|
|
|
|
public function ActivityController_AfterActivityBody_Handler($Sender) {
|
|
|
|
$Activity = $Sender->EventArguments['Activity'];
|
|
|
|
$CurrentUserID = Gdn::Session()->UserID;
|
|
|
|
$Type = 'activity';
|
|
|
|
$ID = $Activity->ActivityID;
|
|
|
|
|
|
|
|
// Only allow reactions on activities that allow comments
|
|
|
|
if($Activity->AllowComments == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check to see if allowed to add reactions
|
2013-11-15 23:14:32 -06:00
|
|
|
if(!Gdn::Session()->CheckPermission('Yaga.Reactions.Add')) {
|
2013-10-25 17:05:01 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Activities can be by multiple users
|
|
|
|
if(is_array($Activity->ActivityUserID) && in_array($CurrentUserID, $Activity->ActivityUserID)) {
|
|
|
|
// User is part of a multiple user activity
|
|
|
|
}
|
|
|
|
else if($CurrentUserID == $Activity->ActivityUserID) {
|
|
|
|
// User is the author of this activity
|
|
|
|
}
|
|
|
|
else {
|
2013-11-20 16:56:02 -06:00
|
|
|
echo Wrap(RenderReactions($ID, $Type, FALSE), 'div', array('class' => 'Reactions'));
|
2013-10-25 17:05:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Insert JS and CSS files into the appropiate controllers
|
|
|
|
*/
|
|
|
|
public function ProfileController_Render_Before($Sender) {
|
|
|
|
$this->_AddResources($Sender);
|
2013-11-13 16:17:08 -06:00
|
|
|
|
2013-11-13 11:25:11 -06:00
|
|
|
if(C('Yaga.Badges.Enabled')) {
|
|
|
|
$Sender->AddModule('BadgesModule');
|
|
|
|
}
|
2013-10-25 17:05:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public function DiscussionController_Render_Before($Sender) {
|
|
|
|
$this->_AddResources($Sender);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function CommentController_Render_Before($Sender) {
|
|
|
|
$this->_AddResources($Sender);
|
|
|
|
}
|
2013-12-09 17:12:22 -06:00
|
|
|
|
2013-11-15 12:52:38 -06:00
|
|
|
public function ActivityController_Render_Before($Sender) {
|
|
|
|
$this->_AddResources($Sender);
|
2013-12-09 17:12:22 -06:00
|
|
|
|
2013-12-03 17:17:16 -06:00
|
|
|
if(C('Yaga.LeaderBoard.Enabled', FALSE)) {
|
|
|
|
// add leaderboard modules to the activity page
|
|
|
|
$Module = new LeaderBoardModule();
|
|
|
|
$Module->GetData('w');
|
|
|
|
$Sender->AddModule($Module);
|
|
|
|
$Module = new LeaderBoardModule();
|
|
|
|
$Sender->AddModule($Module);
|
|
|
|
}
|
2013-11-15 12:52:38 -06:00
|
|
|
}
|
2013-11-11 14:45:31 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check for Badge Awards where appropriate
|
2013-11-11 16:30:16 -06:00
|
|
|
*/
|
2013-11-11 14:45:31 -06:00
|
|
|
public function CommentModel_AfterSaveComment_Handler($Sender) {
|
|
|
|
$this->_AwardBadges($Sender, 'CommentModel_AfterSaveComment');
|
|
|
|
}
|
2013-11-11 16:30:16 -06:00
|
|
|
|
2013-11-11 14:45:31 -06:00
|
|
|
public function DiscussionModel_AfterSaveDiscussion_Handler($Sender) {
|
|
|
|
$this->_AwardBadges($Sender, 'DiscussionModel_AfterSaveDiscussion');
|
|
|
|
}
|
2013-12-09 17:12:22 -06:00
|
|
|
|
2013-11-15 13:56:14 -06:00
|
|
|
public function CommentModel_BeforeNotification_Handler($Sender) {
|
|
|
|
$this->_AwardBadges($Sender, 'CommentModel_BeforeNotification');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function DiscussionModel_BeforeNotification_Handler($Sender) {
|
|
|
|
$this->_AwardBadges($Sender, 'DiscussionModel_BeforeNotification');
|
|
|
|
}
|
2013-11-11 16:30:16 -06:00
|
|
|
|
2013-11-11 14:45:31 -06:00
|
|
|
public function Base_AfterSignIn_Handler($Sender) {
|
|
|
|
$this->_AwardBadges($Sender, 'Base_AfterSignIn');
|
|
|
|
}
|
2013-11-11 16:30:16 -06:00
|
|
|
|
2013-11-11 14:45:31 -06:00
|
|
|
public function UserModel_AfterSave_Handler($Sender) {
|
|
|
|
$this->_AwardBadges($Sender, 'UserModel_AfterSave');
|
|
|
|
}
|
2013-11-11 16:30:16 -06:00
|
|
|
|
2013-11-11 17:34:57 -06:00
|
|
|
public function ReactionModel_AfterReactionSave_Handler($Sender) {
|
|
|
|
$this->_AwardBadges($Sender, 'ReactionModel_AfterReactionSave');
|
2013-11-11 14:45:31 -06:00
|
|
|
}
|
2013-11-11 16:30:16 -06:00
|
|
|
|
2013-12-11 10:28:22 -06:00
|
|
|
public function BadgeAwardModel_AfterBadgeAward_Handler($Sender) {
|
|
|
|
$this->_AwardBadges($Sender, 'BadgeAwardModel_AfterBadgeAward');
|
2013-11-15 17:27:09 -06:00
|
|
|
}
|
2013-12-09 17:12:22 -06:00
|
|
|
|
2013-11-11 14:45:31 -06:00
|
|
|
public function Base_AfterConnection_Handler($Sender) {
|
|
|
|
$this->_AwardBadges($Sender, 'Base_AfterConnection');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the dispatcher to check badge awards
|
2013-11-12 09:11:32 -06:00
|
|
|
*
|
2013-11-13 10:41:39 -06:00
|
|
|
* @param string $Hook The rule hooks to check
|
2013-11-11 14:45:31 -06:00
|
|
|
*/
|
|
|
|
private function _AwardBadges($Sender, $Hook) {
|
2013-12-10 16:50:10 -06:00
|
|
|
if(!C('Yaga.Badges.Enabled')) {
|
2013-11-13 10:43:45 -06:00
|
|
|
return;
|
|
|
|
}
|
2013-11-13 16:17:08 -06:00
|
|
|
|
2013-11-11 14:45:31 -06:00
|
|
|
$Session = Gdn::Session();
|
|
|
|
if(!$Session->IsValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
$UserID = $Session->UserID;
|
|
|
|
$UserModel = new UserModel();
|
|
|
|
$User = $UserModel->GetID($UserID);
|
|
|
|
|
2013-12-11 10:38:16 -06:00
|
|
|
$BadgeAwardModel = Yaga::BadgeAwardModel();
|
2013-12-11 11:54:17 -06:00
|
|
|
$Badges = $BadgeAwardModel->GetUnobtained($UserID);
|
2013-11-11 14:45:31 -06:00
|
|
|
|
|
|
|
$Rules = array();
|
|
|
|
foreach($Badges as $Badge) {
|
2013-12-09 17:12:22 -06:00
|
|
|
if($Badge->Enabled && $Badge->UserID != $UserID) {
|
2013-11-11 14:45:31 -06:00
|
|
|
// The user doesn't have this badge
|
|
|
|
$Class = $Badge->RuleClass;
|
|
|
|
$Criteria = (object) unserialize($Badge->RuleCriteria);
|
|
|
|
|
|
|
|
// Create a rule object if needed
|
|
|
|
if(!in_array($Class, $Rules)) {
|
|
|
|
$Rule = new $Class();
|
|
|
|
$Rules[$Class] = $Rule;
|
|
|
|
}
|
|
|
|
|
|
|
|
// execute the Calculated
|
|
|
|
$Rule = $Rules[$Class];
|
2013-11-11 17:34:57 -06:00
|
|
|
if(in_array($Hook, $Rule->Hooks())) {
|
|
|
|
$Result = $Rule->Award($Sender, $User, $Criteria);
|
|
|
|
if($Result) {
|
|
|
|
if(is_numeric($Result)) {
|
|
|
|
$AwardedUserID = $Result;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$AwardedUserID = $UserID;
|
|
|
|
}
|
2013-12-11 10:38:16 -06:00
|
|
|
$BadgeAwardModel->Award($Badge->BadgeID, $AwardedUserID, $UserID);
|
2013-11-11 17:34:57 -06:00
|
|
|
}
|
2013-11-11 14:45:31 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-12 09:11:32 -06:00
|
|
|
/**
|
|
|
|
* Add the appropriate resources for each controller
|
|
|
|
*
|
|
|
|
* @param object $Sender
|
|
|
|
*/
|
2013-10-25 17:05:01 -05:00
|
|
|
private function _AddResources($Sender) {
|
|
|
|
$Sender->AddCssFile('reactions.css', 'yaga');
|
|
|
|
}
|
2013-11-11 14:45:31 -06:00
|
|
|
|
2013-10-25 17:05:01 -05:00
|
|
|
/**
|
2013-11-12 09:11:32 -06:00
|
|
|
* Add global Yaga resources to all dashboard pages
|
|
|
|
*
|
2013-10-25 17:05:01 -05:00
|
|
|
* @param type $Sender
|
|
|
|
*/
|
|
|
|
public function Base_Render_Before($Sender) {
|
2013-11-12 09:11:32 -06:00
|
|
|
if($Sender->MasterView == 'admin') {
|
|
|
|
$Sender->AddCssFile('yaga.css', 'yaga');
|
|
|
|
}
|
|
|
|
}
|
2013-11-11 14:45:31 -06:00
|
|
|
|
2013-10-24 13:14:52 -05:00
|
|
|
/**
|
2013-11-12 09:11:32 -06:00
|
|
|
* Run the structure and stub scripts if necessary when the application is
|
|
|
|
* enabled.
|
2013-10-24 13:14:52 -05:00
|
|
|
*/
|
|
|
|
public function Setup() {
|
2013-10-25 17:05:01 -05:00
|
|
|
$Config = Gdn::Factory(Gdn::AliasConfig);
|
|
|
|
$Drop = C('Yaga.Version') === FALSE ? TRUE : FALSE;
|
|
|
|
$Explicit = TRUE;
|
2013-10-24 13:14:52 -05:00
|
|
|
include(PATH_APPLICATIONS . DS . 'yaga' . DS . 'settings' . DS . 'structure.php');
|
2013-10-25 17:05:01 -05:00
|
|
|
include(PATH_APPLICATIONS . DS . 'yaga' . DS . 'settings' . DS . 'stub.php');
|
2013-10-24 13:14:52 -05:00
|
|
|
|
2013-10-25 17:05:01 -05:00
|
|
|
$ApplicationInfo = array();
|
|
|
|
include(CombinePaths(array(PATH_APPLICATIONS . DS . 'yaga' . DS . 'settings' . DS . 'about.php')));
|
|
|
|
$Version = ArrayValue('Version', ArrayValue('Yaga', $ApplicationInfo, array()), 'Undefined');
|
|
|
|
SaveToConfig('Yaga.Version', $Version);
|
|
|
|
}
|
2013-12-09 17:12:22 -06:00
|
|
|
}
|