public function getData() { if (Gdn::session()->isValid()) { $BookmarkIDs = Gdn::sql()->select('DiscussionID')->from('UserDiscussion')->where('UserID', Gdn::session()->UserID)->where('Bookmarked', 1)->get()->resultArray(); $BookmarkIDs = consolidateArrayValuesByKey($BookmarkIDs, 'DiscussionID'); if (count($BookmarkIDs)) { $DiscussionModel = new DiscussionModel(); DiscussionModel::CategoryPermissions(); $DiscussionModel->SQL->whereIn('d.DiscussionID', $BookmarkIDs); $Bookmarks = $DiscussionModel->get(0, $this->Limit, array('w.Bookmarked' => '1')); $this->setData('Bookmarks', $Bookmarks); } else { $this->setData('Bookmarks', new Gdn_DataSet()); } } }
/** * Get all tutorials, or a specific one. */ function getTutorials($TutorialCode = '') { // Define all Tutorials $Tutorials = array(array('Code' => 'introduction', 'Name' => 'Introduction to Vanilla', 'Description' => 'This video gives you a brief overview of the Vanilla administrative dashboard and the forum itself.', 'VideoID' => '31043422'), array('Code' => 'using-the-forum', 'Name' => 'Using the Forum', 'Description' => 'Learn how to start, announce, close, edit and delete discussions and comments.', 'VideoID' => '31502992'), array('Code' => 'private-conversations', 'Name' => 'Private Conversations', 'Description' => 'Learn how to start new private conversations and add people to them.', 'VideoID' => '31498383'), array('Code' => 'user-profiles', 'Name' => 'User Profiles', 'Description' => 'Learn how to use and manage your user profile. ', 'VideoID' => '31499266'), array('Code' => 'appearance', 'Name' => 'Changing the appearance of your forum', 'Description' => 'This tutorial takes you through the "Appearance" section of the Vanilla Forums administrative dashboard.', 'VideoID' => '31089641'), array('Code' => 'roles-and-permissions', 'Name' => 'Managing Roles and Permissions in Vanilla', 'Description' => 'This tutorial walks you through how to create new roles and how to use permissions.', 'VideoID' => '31091056'), array('Code' => 'users', 'Name' => 'Finding & Managing Users', 'Description' => 'This tutorial shows you how to search for and manage users.', 'VideoID' => '31094514'), array('Code' => 'category-management-and-advanced-settings', 'Name' => 'Category Management & Advanced Settings', 'Description' => 'Learn how to add, edit, and manage categories. Also learn about advanced forum settings.', 'VideoID' => '31492046'), array('Code' => 'user-registration', 'Name' => 'User Registration', 'Description' => 'Learn to control how new users get into your community.', 'VideoID' => '31493119')); // Default Thumbnails $Thumbnail = Asset('applications/dashboard/design/images/help-tn-200.jpg'); $LargeThumbnail = Asset('applications/dashboard/design/images/help-tn-640.jpg'); for ($i = 0; $i < count($Tutorials); $i++) { $Tutorials[$i]['Thumbnail'] = $Thumbnail; $Tutorials[$i]['LargeThumbnail'] = $LargeThumbnail; } if ($TutorialCode != '') { $Keys = consolidateArrayValuesByKey($Tutorials, 'Code'); $Index = array_search($TutorialCode, $Keys); if ($Index === FALSE) { return FALSE; } // Not found! // Found it, so define it's thumbnail location $Tutorial = val($Index, $Tutorials); $VideoID = val('VideoID', $Tutorial); try { $videoInfo = json_decode(file_get_contents("http://vimeo.com/api/v2/video/{$Tutorial['VideoID']}.json")); if ($videoInfo && ($vimeo = array_shift($videoInfo))) { $Tutorial['Thumbnail'] = str_replace('http://', '//', val('thumbnail_medium', $vimeo)); $Tutorial['LargeThumbnail'] = str_replace('http://', '//', val('thumbnail_large', $vimeo)); } } catch (Exception $Ex) { // Do nothing } return $Tutorial; } else { // Loop through each tutorial populating the thumbnail image location try { foreach ($Tutorials as $Key => &$Tutorial) { $videoInfo = json_decode(file_get_contents("http://vimeo.com/api/v2/video/{$Tutorial['VideoID']}.json")); if ($videoInfo && ($vimeo = array_shift($videoInfo))) { $Tutorial['Thumbnail'] = str_replace('http://', '//', val('thumbnail_medium', $vimeo)); $Tutorial['LargeThumbnail'] = str_replace('http://', '//', val('thumbnail_large', $vimeo)); } } } catch (Exception $Ex) { // Do nothing } return $Tutorials; } }
/** * Delete all of the Vanilla related information for a specific user. * * @since 2.1 * * @param int $UserID The ID of the user to delete. * @param array $Options An array of options: * - DeleteMethod: One of delete, wipe, or NULL */ public function deleteUserData($UserID, $Options = array(), &$Data = null) { $SQL = Gdn::sql(); // Remove discussion watch records and drafts. $SQL->delete('UserDiscussion', array('UserID' => $UserID)); Gdn::userModel()->GetDelete('Draft', array('InsertUserID' => $UserID), $Data); // Comment deletion depends on method selected $DeleteMethod = val('DeleteMethod', $Options, 'delete'); if ($DeleteMethod == 'delete') { // Clear out the last posts to the categories. $SQL->update('Category c')->join('Discussion d', 'd.DiscussionID = c.LastDiscussionID')->where('d.InsertUserID', $UserID)->set('c.LastDiscussionID', null)->set('c.LastCommentID', null)->put(); $SQL->update('Category c')->join('Comment d', 'd.CommentID = c.LastCommentID')->where('d.InsertUserID', $UserID)->set('c.LastDiscussionID', null)->set('c.LastCommentID', null)->put(); // Grab all of the discussions that the user has engaged in. $DiscussionIDs = $SQL->select('DiscussionID')->from('Comment')->where('InsertUserID', $UserID)->groupBy('DiscussionID')->get()->resultArray(); $DiscussionIDs = consolidateArrayValuesByKey($DiscussionIDs, 'DiscussionID'); Gdn::userModel()->GetDelete('Comment', array('InsertUserID' => $UserID), $Data); // Update the comment counts. $CommentCounts = $SQL->select('DiscussionID')->select('CommentID', 'count', 'CountComments')->select('CommentID', 'max', 'LastCommentID')->whereIn('DiscussionID', $DiscussionIDs)->groupBy('DiscussionID')->get('Comment')->resultArray(); foreach ($CommentCounts as $Row) { $SQL->put('Discussion', array('CountComments' => $Row['CountComments'] + 1, 'LastCommentID' => $Row['LastCommentID']), array('DiscussionID' => $Row['DiscussionID'])); } // Update the last user IDs. $SQL->update('Discussion d')->join('Comment c', 'd.LastCommentID = c.CommentID', 'left')->set('d.LastCommentUserID', 'c.InsertUserID', false, false)->set('d.DateLastComment', 'c.DateInserted', false, false)->whereIn('d.DiscussionID', $DiscussionIDs)->put(); // Update the last posts. $Discussions = $SQL->whereIn('DiscussionID', $DiscussionIDs)->where('LastCommentUserID', $UserID)->get('Discussion'); // Delete the user's dicussions Gdn::userModel()->GetDelete('Discussion', array('InsertUserID' => $UserID), $Data); // Update the appropriat recent posts in the categories. $CategoryModel = new CategoryModel(); $Categories = $CategoryModel->getWhere(array('LastDiscussionID' => null))->resultArray(); foreach ($Categories as $Category) { $CategoryModel->SetRecentPost($Category['CategoryID']); } } elseif ($DeleteMethod == 'wipe') { // Erase the user's dicussions $SQL->update('Discussion')->set('Body', t('The user and all related content has been deleted.'))->set('Format', 'Deleted')->where('InsertUserID', $UserID)->put(); $SQL->update('Comment')->set('Body', t('The user and all related content has been deleted.'))->set('Format', 'Deleted')->where('InsertUserID', $UserID)->put(); } else { // Leave comments } // Remove the user's profile information related to this application $SQL->update('User')->set(array('CountDiscussions' => 0, 'CountUnreadDiscussions' => 0, 'CountComments' => 0, 'CountDrafts' => 0, 'CountBookmarks' => 0))->where('UserID', $UserID)->put(); }
/** * * * @param null $AddonCode * @param bool $Explicit * @param bool $Drop * @throws Exception */ public function runStructure($AddonCode = null, $Explicit = false, $Drop = false) { // Get the structure files for all of the enabled applications. $ApplicationManager = new Gdn_ApplicationManager(); $Apps = $ApplicationManager->EnabledApplications(); $AppNames = consolidateArrayValuesByKey($Apps, 'Folder'); $Paths = array(); foreach ($Apps as $Key => $AppInfo) { $Path = PATH_APPLICATIONS . "/{$AppInfo['Folder']}/settings/structure.php"; if (file_exists($Path)) { $Paths[] = $Path; } Gdn::ApplicationManager()->RegisterPermissions($Key, $this->Validation); } // Execute the structures. $Database = Gdn::database(); $SQL = Gdn::sql(); $Structure = Gdn::structure(); foreach ($Paths as $Path) { include $Path; } // Execute the structures for all of the plugins. $PluginManager = Gdn::pluginManager(); $Registered = $PluginManager->RegisteredPlugins(); foreach ($Registered as $ClassName => $Enabled) { if (!$Enabled) { continue; } try { $Plugin = $PluginManager->GetPluginInstance($ClassName, Gdn_PluginManager::ACCESS_CLASSNAME); if (method_exists($Plugin, 'Structure')) { trace("{$ClassName}->Structure()"); $Plugin->Structure(); } } catch (Exception $Ex) { // Do nothing, plugin wouldn't load/structure. if (Debug()) { throw $Ex; } } } $this->fireEvent('AfterStructure'); }
/** * Gets announced discussions. * * @since 2.0.0 * @access public * * @param array $Wheres SQL conditions. * @return object SQL result. */ public function getAnnouncements($Wheres = '') { $Session = Gdn::session(); $Limit = Gdn::config('Vanilla.Discussions.PerPage', 50); $Offset = 0; $UserID = $Session->UserID > 0 ? $Session->UserID : 0; $CategoryID = val('d.CategoryID', $Wheres, 0); $GroupID = val('d.GroupID', $Wheres, 0); // Get the discussion IDs of the announcements. $CacheKey = $this->GetAnnouncementCacheKey($CategoryID); if ($GroupID == 0) { $this->SQL->Cache($CacheKey); } $this->SQL->select('d.DiscussionID')->from('Discussion d'); if (!is_array($CategoryID) && ($CategoryID > 0 || $GroupID > 0)) { $this->SQL->where('d.Announce >', '0'); } else { $this->SQL->where('d.Announce', 1); } if ($GroupID > 0) { $this->SQL->where('d.GroupID', $GroupID); } elseif (is_array($CategoryID) || $CategoryID > 0) { $this->SQL->where('d.CategoryID', $CategoryID); } $AnnouncementIDs = $this->SQL->get()->resultArray(); $AnnouncementIDs = consolidateArrayValuesByKey($AnnouncementIDs, 'DiscussionID'); // Short circuit querying when there are no announcements. if (count($AnnouncementIDs) == 0) { return new Gdn_DataSet(); } $this->DiscussionSummaryQuery(array(), false); if (!empty($Wheres)) { $this->SQL->where($Wheres); } if ($UserID) { $this->SQL->select('w.UserID', '', 'WatchUserID')->select('w.DateLastViewed, w.Dismissed, w.Bookmarked')->select('w.CountComments', '', 'CountCommentWatch')->select('w.Participated')->join('UserDiscussion w', 'd.DiscussionID = w.DiscussionID and w.UserID = ' . $UserID, 'left'); } else { // Don't join in the user table when we are a guest. $this->SQL->select('null as WatchUserID, null as DateLastViewed, null as Dismissed, null as Bookmarked, null as CountCommentWatch'); } // Add conditions passed. // if (is_array($Wheres)) // $this->SQL->where($Wheres); // // $this->SQL // ->where('d.Announce', '1'); $this->SQL->whereIn('d.DiscussionID', $AnnouncementIDs); // If we aren't viewing announcements in a category then only show global announcements. if (!$Wheres || is_array($CategoryID)) { $this->SQL->where('d.Announce', 1); } else { $this->SQL->where('d.Announce >', 0); } // If we allow users to dismiss discussions, skip ones this user dismissed if (c('Vanilla.Discussions.Dismiss', 1) && $UserID) { $this->SQL->where('coalesce(w.Dismissed, \'0\')', '0', false); } $this->SQL->orderBy(self::GetSortField(), 'desc')->limit($Limit, $Offset); $Data = $this->SQL->get(); // Save the announcements that were fetched for later removal. $AnnouncementIDs = array(); foreach ($Data as $Row) { $AnnouncementIDs[] = val('DiscussionID', $Row); } $this->_AnnouncementIDs = $AnnouncementIDs; $this->AddDiscussionColumns($Data); if (c('Vanilla.Views.Denormalize', false)) { $this->AddDenormalizedViews($Data); } Gdn::userModel()->joinUsers($Data, array('FirstUserID', 'LastUserID')); CategoryModel::JoinCategories($Data); // Prep and fire event $this->EventArguments['Data'] = $Data; $this->fireEvent('AfterAddColumns'); return $Data; }
<?php if (!defined('APPLICATION')) { exit; } require_once $this->fetchViewLocation('helper_functions'); $Tutorials = GetTutorials(); // Figure out the current video $CurrentTutorialCode = $this->data('CurrentTutorial'); $Keys = consolidateArrayValuesByKey($Tutorials, 'Code'); $Index = array_search($CurrentTutorialCode, $Keys); if (!$Index) { $Index = 0; } $CurrentTutorial = val($Index, $Tutorials); $CurrentTutorialCode = val('Code', $CurrentTutorial, ''); ?> <style type="text/css"> div.Tutorials { padding: 20px; } .Video { margin-right: 20px; float: left; } .VideoInfo { min-height: 420px; }
/** * Show all categories and few discussions from each. * * @param string $Category The url code of the parent category. * @since 2.0.0 * @access public */ public function discussions($Category = '') { // Setup head $this->addJsFile('discussions.js'); $this->Menu->highlightRoute('/discussions'); if (!$this->title()) { $Title = c('Garden.HomepageTitle'); if ($Title) { $this->title($Title, ''); } else { $this->title(t('All Categories')); } } if (!$Category) { $this->Description(c('Garden.Description', null)); } Gdn_Theme::section('CategoryDiscussionList'); // Set the category follow toggle before we load category data so that it affects the category query appropriately. $CategoryFollowToggleModule = new CategoryFollowToggleModule($this); $CategoryFollowToggleModule->SetToggle(); $this->CategoryModel->Watching = !Gdn::session()->GetPreference('ShowAllCategories'); if ($Category) { $Subtree = CategoryModel::GetSubtree($Category, false); $CategoryIDs = consolidateArrayValuesByKey($Subtree, 'CategoryID'); $Categories = $this->CategoryModel->GetFull($CategoryIDs)->resultArray(); } else { $Categories = $this->CategoryModel->GetFull()->resultArray(); } $this->setData('Categories', $Categories); // Get category data and discussions $this->DiscussionsPerCategory = c('Vanilla.Discussions.PerCategory', 5); $DiscussionModel = new DiscussionModel(); $this->CategoryDiscussionData = array(); foreach ($this->CategoryData->result() as $Category) { if ($Category->CategoryID > 0) { $this->CategoryDiscussionData[$Category->CategoryID] = $DiscussionModel->get(0, $this->DiscussionsPerCategory, array('d.CategoryID' => $Category->CategoryID, 'Announce' => 'all')); } } // Add modules $this->addModule('NewDiscussionModule'); $this->addModule('DiscussionFilterModule'); $this->addModule('CategoriesModule'); $this->addModule('BookmarkedModule'); $this->addModule($CategoryFollowToggleModule); // Set view and render $this->View = 'discussions'; $this->canonicalUrl(url('/categories', true)); $Path = $this->fetchViewLocation('helper_functions', 'discussions', false, false); if ($Path) { include_once $Path; } // For GetOptions function $Path2 = $this->fetchViewLocation('helper_functions', 'categories', false, false); if ($Path2) { include_once $Path2; } $this->render(); }
public function counts($Column) { $Result = array('Complete' => true); switch ($Column) { case 'CountDiscussions': $this->Database->query(DBAModel::GetCountSQL('count', 'Category', 'Discussion')); break; case 'CountComments': $this->Database->query(DBAModel::GetCountSQL('sum', 'Category', 'Discussion', $Column, 'CountComments')); break; case 'LastDiscussionID': $this->Database->query(DBAModel::GetCountSQL('max', 'Category', 'Discussion')); break; case 'LastCommentID': $Data = $this->SQL->select('d.CategoryID')->select('c.CommentID', 'max', 'LastCommentID')->select('d.DiscussionID', 'max', 'LastDiscussionID')->select('c.DateInserted', 'max', 'DateLastComment')->select('d.DateInserted', 'max', 'DateLastDiscussion')->from('Comment c')->join('Discussion d', 'd.DiscussionID = c.DiscussionID')->groupBy('d.CategoryID')->get()->resultArray(); // Now we have to grab the discussions associated with these comments. $CommentIDs = consolidateArrayValuesByKey($Data, 'LastCommentID'); // Grab the discussions for the comments. $this->SQL->select('c.CommentID, c.DiscussionID')->from('Comment c')->whereIn('c.CommentID', $CommentIDs); $Discussions = $this->SQL->get()->resultArray(); $Discussions = Gdn_DataSet::Index($Discussions, array('CommentID')); foreach ($Data as $Row) { $CategoryID = (int) $Row['CategoryID']; $Category = CategoryModel::categories($CategoryID); $CommentID = $Row['LastCommentID']; $DiscussionID = valr("{$CommentID}.DiscussionID", $Discussions, null); $DateLastComment = Gdn_Format::toTimestamp($Row['DateLastComment']); $DateLastDiscussion = Gdn_Format::toTimestamp($Row['DateLastDiscussion']); $Set = array('LastCommentID' => $CommentID); if ($DiscussionID) { $LastDiscussionID = val('LastDiscussionID', $Category); if ($DateLastComment >= $DateLastDiscussion) { // The most recent discussion is from this comment. $Set['LastDiscussionID'] = $DiscussionID; } else { // The most recent discussion has no comments. $Set['LastCommentID'] = null; } } else { // Something went wrong. $Set['LastCommentID'] = null; $Set['LastDiscussionID'] = null; } $this->setField($CategoryID, $Set); } break; case 'LastDateInserted': $Categories = $this->SQL->select('ca.CategoryID')->select('d.DateInserted', '', 'DateLastDiscussion')->select('c.DateInserted', '', 'DateLastComment')->from('Category ca')->join('Discussion d', 'd.DiscussionID = ca.LastDiscussionID')->join('Comment c', 'c.CommentID = ca.LastCommentID')->get()->resultArray(); foreach ($Categories as $Category) { $DateLastDiscussion = val('DateLastDiscussion', $Category); $DateLastComment = val('DateLastComment', $Category); $MaxDate = $DateLastComment; if (is_null($DateLastComment) || $DateLastDiscussion > $MaxDate) { $MaxDate = $DateLastDiscussion; } if (is_null($MaxDate)) { continue; } $CategoryID = (int) $Category['CategoryID']; $this->setField($CategoryID, 'LastDateInserted', $MaxDate); } break; } self::ClearCache(); return $Result; }
/** * * * @param $UserID * @param $RoleIDs * @param $RecordEvent */ public function saveRoles($UserID, $RoleIDs, $RecordEvent) { if (is_string($RoleIDs) && !is_numeric($RoleIDs)) { // The $RoleIDs are a comma delimited list of role names. $RoleNames = array_map('trim', explode(',', $RoleIDs)); $RoleIDs = $this->SQL->select('r.RoleID')->from('Role r')->whereIn('r.Name', $RoleNames)->get()->resultArray(); $RoleIDs = consolidateArrayValuesByKey($RoleIDs, 'RoleID'); } if (!is_array($RoleIDs)) { $RoleIDs = array($RoleIDs); } // Get the current roles. $OldRoleIDs = array(); $OldRoleData = $this->SQL->select('ur.RoleID, r.Name')->from('Role r')->join('UserRole ur', 'r.RoleID = ur.RoleID')->where('ur.UserID', $UserID)->get()->resultArray(); if ($OldRoleData !== false) { $OldRoleIDs = consolidateArrayValuesByKey($OldRoleData, 'RoleID'); } // 1a) Figure out which roles to delete. $DeleteRoleIDs = array_diff($OldRoleIDs, $RoleIDs); // 1b) Remove old role associations for this user. if (count($DeleteRoleIDs) > 0) { $this->SQL->whereIn('RoleID', $DeleteRoleIDs)->delete('UserRole', array('UserID' => $UserID)); } // 2a) Figure out which roles to insert. $InsertRoleIDs = array_diff($RoleIDs, $OldRoleIDs); // 2b) Insert the new role associations for this user. foreach ($InsertRoleIDs as $InsertRoleID) { if (is_numeric($InsertRoleID)) { $this->SQL->insert('UserRole', array('UserID' => $UserID, 'RoleID' => $InsertRoleID)); } } $this->clearCache($UserID, array('roles', 'permissions')); if ($RecordEvent && (count($DeleteRoleIDs) > 0 || count($InsertRoleIDs) > 0)) { $User = $this->getID($UserID); $Session = Gdn::session(); $OldRoles = false; if ($OldRoleData !== false) { $OldRoles = consolidateArrayValuesByKey($OldRoleData, 'Name'); } $NewRoles = false; $NewRoleData = $this->SQL->select('r.RoleID, r.Name')->from('Role r')->join('UserRole ur', 'r.RoleID = ur.RoleID')->where('ur.UserID', $UserID)->get()->resultArray(); if ($NewRoleData !== false) { $NewRoles = consolidateArrayValuesByKey($NewRoleData, 'Name'); } $RemovedRoles = array_diff($OldRoles, $NewRoles); $NewRoles = array_diff($NewRoles, $OldRoles); foreach ($RemovedRoles as $RoleName) { Logger::event('role_remove', Logger::INFO, "{username} removed {toUsername} from the {role} role.", array('toUsername' => $User->Name, 'role' => $RoleName)); } foreach ($NewRoles as $RoleName) { Logger::event('role_add', Logger::INFO, "{username} added {toUsername} to the {role} role.", array('toUsername' => $User->Name, 'role' => $RoleName)); } $RemovedCount = count($RemovedRoles); $NewCount = count($NewRoles); $Story = ''; if ($RemovedCount > 0 && $NewCount > 0) { $Story = sprintf(t('%1$s was removed from the %2$s %3$s and added to the %4$s %5$s.'), $User->Name, implode(', ', $RemovedRoles), plural($RemovedCount, 'role', 'roles'), implode(', ', $NewRoles), plural($NewCount, 'role', 'roles')); } elseif ($RemovedCount > 0) { $Story = sprintf(t('%1$s was removed from the %2$s %3$s.'), $User->Name, implode(', ', $RemovedRoles), plural($RemovedCount, 'role', 'roles')); } elseif ($NewCount > 0) { $Story = sprintf(t('%1$s was added to the %2$s %3$s.'), $User->Name, implode(', ', $NewRoles), plural($NewCount, 'role', 'roles')); } } }
/** * * * @param $Users * @param string $UserIDColumn * @param string $RolesColumn */ public static function setUserRoles(&$Users, $UserIDColumn = 'UserID', $RolesColumn = 'Roles') { $UserIDs = array_unique(ConsolidateArrayValuesByKey($Users, $UserIDColumn)); // Try and get all of the mappings from the cache. $Keys = array(); foreach ($UserIDs as $UserID) { $Keys[$UserID] = formatString(UserModel::USERROLES_KEY, array('UserID' => $UserID)); } $UserRoles = Gdn::cache()->get($Keys); if (!is_array($UserRoles)) { $UserRoles = array(); } // Grab all of the data that doesn't exist from the DB. $MissingIDs = array(); foreach ($Keys as $UserID => $Key) { if (!array_key_exists($Key, $UserRoles)) { $MissingIDs[$UserID] = $Key; } } if (count($MissingIDs) > 0) { $DbUserRoles = Gdn::sql()->select('ur.*')->from('UserRole ur')->whereIn('ur.UserID', array_keys($MissingIDs))->get()->resultArray(); $DbUserRoles = Gdn_DataSet::Index($DbUserRoles, 'UserID', array('Unique' => false)); // Store the user role mappings. foreach ($DbUserRoles as $UserID => $Rows) { $RoleIDs = consolidateArrayValuesByKey($Rows, 'RoleID'); $Key = $Keys[$UserID]; Gdn::cache()->store($Key, $RoleIDs); $UserRoles[$Key] = $RoleIDs; } } $AllRoles = self::roles(); // roles indexed by role id. // Skip personal info roles if (!checkPermission('Garden.PersonalInfo.View')) { $AllRoles = array_filter($AllRoles, 'self::FilterPersonalInfo'); } // Join the users. foreach ($Users as &$User) { $UserID = val($UserIDColumn, $User); $Key = $Keys[$UserID]; $RoleIDs = val($Key, $UserRoles, array()); $Roles = array(); foreach ($RoleIDs as $RoleID) { if (!array_key_exists($RoleID, $AllRoles)) { continue; } $Roles[$RoleID] = $AllRoles[$RoleID]['Name']; } setValue($RolesColumn, $User, $Roles); } }
/** * Retrieves UserMeta information for a UserID / Key pair. * * This method takes a $UserID or array of $UserIDs, and a $Key. It converts the * $Key to fully qualified format and then queries for the associated value(s). $Key * can contain SQL wildcards, in which case multiple results can be returned. * * If $UserID is an array, the return value will be a multi dimensional array with the first * axis containing UserIDs and the second containing fully qualified UserMetaKeys, associated with * their values. * * If $UserID is a scalar, the return value will be a single dimensional array of $UserMetaKey => $Value * pairs. * * @param $UserID integer UserID or array of UserIDs * @param $Key string relative user meta key * @param $Default optional default return value if key is not found * @return array results or $Default */ public function getUserMeta($UserID, $Key = null, $Default = null) { if (Gdn::cache()->activeEnabled()) { if (is_array($UserID)) { $Result = array(); foreach ($UserID as $ID) { $Meta = $this->GetUserMeta($ID, $Key, $Default); $Result[$ID] = $Meta; } return $Result; } // Try and grab the user meta from the cache. $CacheKey = 'UserMeta_' . $UserID; $UserMeta = Gdn::cache()->get($CacheKey); if ($UserMeta === Gdn_Cache::CACHEOP_FAILURE) { $UserMeta = $this->getWhere(array('UserID' => $UserID), 'Name')->resultArray(); $UserMeta = consolidateArrayValuesByKey($UserMeta, 'Name', 'Value'); Gdn::cache()->store($CacheKey, $UserMeta); } if ($Key === null) { return $UserMeta; } if (strpos($Key, '%') === false) { $Result = val($Key, $UserMeta, $Default); return array($Key => $Result); } $Regex = '`' . str_replace('%', '.*', preg_quote($Key)) . '`i'; $Result = array(); foreach ($UserMeta as $Name => $Value) { if (preg_match($Regex, $Name)) { $Result[$Name] = $Value; } } return $Result; } $Sql = clone Gdn::sql(); $Sql->reset(); $UserMetaQuery = $Sql->select('*')->from('UserMeta u'); if (is_array($UserID)) { $UserMetaQuery->whereIn('u.UserID', $UserID); } else { $UserMetaQuery->where('u.UserID', $UserID); } if (stristr($Key, '%')) { $UserMetaQuery->where('u.Name like', $Key); } else { $UserMetaQuery->where('u.Name', $Key); } $UserMetaData = $UserMetaQuery->get(); $UserMeta = array(); if ($UserMetaData->numRows()) { if (is_array($UserID)) { while ($MetaRow = $UserMetaData->NextRow()) { $UserMeta[$MetaRow->UserID][$MetaRow->Name] = $MetaRow->Value; } } else { while ($MetaRow = $UserMetaData->NextRow()) { $UserMeta[$MetaRow->Name] = $MetaRow->Value; } } } else { self::$MemoryCache[$Key] = $Default; $UserMeta[$Key] = $Default; } unset($UserMetaData); return $UserMeta; }
/** * Select content based on author RankID. * * @param array|int $Parameters * @return array|false */ protected function selectByRank($Parameters) { // Must have Ranks enabled. if (!class_exists('RankModel')) { return false; } if (!is_array($Parameters)) { $RankID = $Parameters; } else { $RankID = val('RankID', $Parameters, null); } // Check for Rank passed by name. if (!is_numeric($RankID)) { $RankModel = new RankModel(); $Rank = $RankModel->getWhere(array('Name' => $RankID))->firstRow(); $RankID = val('RankID', $Rank); } // Disallow blank or multiple ranks. if (!$RankID || is_array($RankID)) { return false; } // Check cache $SelectorRankCacheKey = "modules.promotedcontent.rank.{$RankID}"; $Content = Gdn::cache()->get($SelectorRankCacheKey); if ($Content == Gdn_Cache::CACHEOP_FAILURE) { // Get everyone with this Role $UserIDs = Gdn::sql()->select('u.UserID')->from('User u')->where('u.RankID', $RankID)->groupBy('UserID')->get()->result(DATASET_TYPE_ARRAY); $UserIDs = consolidateArrayValuesByKey($UserIDs, 'UserID'); // Get matching Discussions $Discussions = array(); if ($this->ShowDiscussions()) { $Discussions = Gdn::sql()->select('d.*')->from('Discussion d')->whereIn('d.InsertUserID', $UserIDs)->orderBy('DateInserted', 'DESC')->limit($this->Limit)->get()->result(DATASET_TYPE_ARRAY); } // Get matching Comments $Comments = array(); if ($this->ShowComments()) { $Comments = Gdn::sql()->select('c.*')->from('Comment c')->whereIn('InsertUserID', $UserIDs)->orderBy('DateInserted', 'DESC')->limit($this->Limit)->get()->result(DATASET_TYPE_ARRAY); $this->JoinCategory($Comments); } // Interleave $Content = $this->Union('DateInserted', array('Discussion' => $Discussions, 'Comment' => $Comments)); $this->processContent($Content); // Add result to cache Gdn::cache()->store($SelectorRankCacheKey, $Content, array(Gdn_Cache::FEATURE_EXPIRY => $this->Expiry)); } $this->Security($Content); $this->Condense($Content, $this->Limit); return $Content; }
/** * * * @param Gdn_SQLDriver $Sql */ public function setTagSql($Sql, $Tag, &$Limit, &$Offset = 0, $Op = 'or') { $SortField = 'd.DateLastComment'; $SortDirection = 'desc'; $TagSql = clone Gdn::sql(); if ($DateFrom = Gdn::request()->get('DateFrom')) { // Find the discussion ID of the first discussion created on or after the date from. $DiscussionIDFrom = $TagSql->getWhere('Discussion', array('DateInserted >= ' => $DateFrom), 'DiscussionID', 'asc', 1)->value('DiscussionID'); $SortField = 'd.DiscussionID'; } if (!is_array($Tag)) { $Tags = array_map('trim', explode(',', $Tag)); } $TagIDs = $TagSql->select('TagID')->from('Tag')->whereIn('Name', $Tags)->get()->resultArray(); $TagIDs = consolidateArrayValuesByKey($TagIDs, 'TagID'); if ($Op == 'and' && count($Tags) > 1) { $DiscussionIDs = $TagSql->select('DiscussionID')->select('TagID', 'count', 'CountTags')->from('TagDiscussion')->whereIn('TagID', $TagIDs)->groupBy('DiscussionID')->having('CountTags >=', count($Tags))->limit($Limit, $Offset)->orderBy('DiscussionID', 'desc')->get()->resultArray(); $Limit = ''; $Offset = 0; $DiscussionIDs = consolidateArrayValuesByKey($DiscussionIDs, 'DiscussionID'); $Sql->whereIn('d.DiscussionID', $DiscussionIDs); $SortField = 'd.DiscussionID'; } else { $Sql->join('TagDiscussion td', 'd.DiscussionID = td.DiscussionID')->limit($Limit, $Offset)->whereIn('td.TagID', $TagIDs); if ($Op == 'and') { $SortField = 'd.DiscussionID'; } } // Set up the sort field and direction. saveToConfig(array('Vanilla.Discussions.SortField' => $SortField, 'Vanilla.Discussions.SortDirection' => $SortDirection), '', false); }
<?php if (!defined('APPLICATION')) { exit; } ?> <h1><?php echo $this->data('Title'); ?> </h1> <?php echo $this->Form->open(); echo $this->Form->errors(); $Discussions = $this->data('Discussions'); if (count($Discussions) < 2) { echo wrap(t('You have to select at least 2 discussions to merge.'), 'p'); } else { echo wrap(t('Choose the main discussion into which all comments will be merged:'), 'p'); $DefaultDiscussionID = $Discussions[0]['DiscussionID']; $RadioData = consolidateArrayValuesByKey($Discussions, 'DiscussionID', 'Name'); array_map('htmlspecialchars', $RadioData); echo '<ul><li>'; echo $this->Form->RadioList('MergeDiscussionID', $RadioData, array('ValueField' => 'DiscussionID', 'TextField' => 'Name', 'Default' => $DefaultDiscussionID)); echo '</li></ul>'; echo '<div class="P">' . $this->Form->checkBox('RedirectLink', 'Leave a redirect links from the old discussions.') . '</div>'; echo '<div class="Buttons">' . $this->Form->button('Merge') . '</div>'; } echo $this->Form->close();
<dd class="LastActive"><?php echo Gdn_Format::date($this->User->DateLastActive, 'html'); ?> </dd> <dt class="Roles"><?php echo t('Roles'); ?> </dt> <dd class="Roles"><?php if (Gdn::session()->checkPermission('Garden.Moderation.Manage')) { echo UserVerified($this->User) . ', '; } if (empty($this->Roles)) { echo t('No Roles'); } else { echo htmlspecialchars(implode(', ', consolidateArrayValuesByKey($this->Roles, 'Name'))); } ?> </dd> <?php if ($Points = valr('User.Points', $this, 0)) { // Only show positive point totals ?> <dt class="Points"><?php echo t('Points'); ?> </dt> <dd class="Points"><?php echo number_format($Points); ?> </dd>