/** * Permission checks & property prep. */ public function __construct() { parent::__construct(); $this->_MediaCache = NULL; $this->CanUpload = Gdn::Session()->CheckPermission('Plugins.Attachments.Upload.Allow', FALSE); $this->CanDownload = Gdn::Session()->CheckPermission('Plugins.Attachments.Download.Allow', FALSE); if ($this->CanUpload) { $PermissionCategory = CategoryModel::PermissionCategory(Gdn::Controller()->Data('Category')); if (!GetValue('AllowFileUploads', $PermissionCategory, TRUE)) { $this->CanUpload = FALSE; } } }
/** * Render the module. * * @return string */ public function toString() { // Set CategoryID if we have one. if ($this->CategoryID === null) { $this->CategoryID = Gdn::controller()->data('Category.CategoryID', false); } // Allow plugins and themes to modify parameters. Gdn::controller()->EventArguments['NewDiscussionModule'] =& $this; Gdn::controller()->fireEvent('BeforeNewDiscussionButton'); // Make sure the user has the most basic of permissions first. $PermissionCategory = CategoryModel::PermissionCategory($this->CategoryID); if ($this->CategoryID) { $Category = CategoryModel::categories($this->CategoryID); $HasPermission = Gdn::session()->checkPermission('Vanilla.Discussions.Add', true, 'Category', val('CategoryID', $PermissionCategory)); } else { $HasPermission = Gdn::session()->checkPermission('Vanilla.Discussions.Add', true, 'Category', 'any'); } // Determine if this is a guest & we're using "New Discussion" button as call to action. $PrivilegedGuest = $this->ShowGuests && !Gdn::session()->isValid(); // No module for you! if (!$HasPermission && !$PrivilegedGuest) { return ''; } // Grab the allowed discussion types. $DiscussionTypes = CategoryModel::AllowedDiscussionTypes($PermissionCategory); foreach ($DiscussionTypes as $Key => $Type) { if (isset($Type['AddPermission']) && !Gdn::session()->checkPermission($Type['AddPermission'])) { unset($DiscussionTypes[$Key]); continue; } // If user !$HasPermission, they are $PrivilegedGuest so redirect to $GuestUrl. $Url = $HasPermission ? val('AddUrl', $Type) : $this->GuestUrl; if (!$Url) { continue; } if (isset($Category) && $HasPermission) { $Url .= '/' . rawurlencode(val('UrlCode', $Category)); } $this->AddButton(t(val('AddText', $Type)), $Url); } // Add QueryString to URL if one is defined. if ($this->QueryString && $HasPermission) { foreach ($this->Buttons as &$Row) { $Row['Url'] .= (strpos($Row['Url'], '?') !== false ? '&' : '?') . $this->QueryString; } } return parent::ToString(); }
public function ToString() { if ($this->CategoryID === NULL) { $this->CategoryID = Gdn::Controller()->Data('Category.CategoryID', FALSE); } Gdn::Controller()->EventArguments['NewDiscussionModule'] =& $this; Gdn::Controller()->FireEvent('BeforeNewDiscussionButton'); // Make sure the user has the most basic of permissions first. $PermissionCategory = CategoryModel::PermissionCategory($this->CategoryID); if ($this->CategoryID) { $Category = CategoryModel::Categories($this->CategoryID); $HasPermission = Gdn::Session()->CheckPermission('Vanilla.Discussions.Add', TRUE, 'Category', GetValue('CategoryID', $PermissionCategory)); } else { $HasPermission = Gdn::Session()->CheckPermission('Vanilla.Discussions.Add', TRUE, 'Category', 'any'); } if (!$HasPermission) { return ''; } // Grab the allowed discussion types. $DiscussionTypes = CategoryModel::AllowedDiscussionTypes($PermissionCategory); foreach ($DiscussionTypes as $Key => $Type) { if (isset($Type['AddPermission']) && !Gdn::Session()->CheckPermission($Type['AddPermission'])) { unset($DiscussionTypes[$Key]); continue; } $Url = GetValue('AddUrl', $Type); if (!$Url) { continue; } if (isset($Category)) { $Url .= '/' . rawurlencode(GetValue('UrlCode', $Category)); } $this->AddButton(T(GetValue('AddText', $Type)), $Url); } if ($this->QueryString) { foreach ($this->Buttons as &$Row) { $Row['Url'] .= (strpos($Row['Url'], '?') !== FALSE ? '&' : '?') . $this->QueryString; } } return parent::ToString(); }