Permalink
Browse files

Merge branch 'master' of github.com:vanillaforums/Garden

  • Loading branch information...
2 parents ec7561d + 73bfae4 commit 483834dd9ddf5411a3f3fe2661d5bccc1381ca0c @tburry tburry committed Oct 8, 2012
@@ -770,6 +770,67 @@ public function GetFull($CategoryID = FALSE, $Permissions = FALSE) {
return $Result;
}
+ /**
+ * Get a list of categories, considering several filters
+ *
+ * @param array $RestrictIDs Optional list of category ids to mask the dataset
+ * @param string $Permissions Optional permission to require. Defaults to Vanilla.Discussions.View.
+ * @param array $ExcludeWhere Exclude categories with any of these flags
+ * @return \Gdn_DataSet
+ */
+ public function GetFiltered($RestrictIDs = FALSE, $Permissions = FALSE, $ExcludeWhere = FALSE) {
+
+ // Get the current category list
+ $Categories = self::Categories();
+
+ // Filter out the categories we aren't supposed to view.
+ if ($RestrictIDs && !is_array($RestrictIDs))
+ $RestrictIDs = array($RestrictIDs);
+ elseif ($this->Watching)
+ $RestrictIDs = self::CategoryWatch();
+
+ switch ($Permissions) {
+ case 'Vanilla.Discussions.Add':
+ $Permissions = 'PermsDiscussionsAdd';
+ break;
+ case 'Vanilla.Disussions.Edit':
+ $Permissions = 'PermsDiscussionsEdit';
+ break;
+ default:
+ $Permissions = 'PermsDiscussionsView';
+ break;
+ }
+
+ $IDs = array_keys($Categories);
+ foreach ($IDs as $ID) {
+
+ // Exclude the root category
+ if ($ID < 0)
+ unset($Categories[$ID]);
+
+ // No categories where we don't have permission
+ elseif (!$Categories[$ID][$Permissions])
+ unset($Categories[$ID]);
+
+ // No categories whose filter fields match the provided filter values
+ elseif (is_array($ExcludeWhere)) {
+ foreach ($ExcludeWhere as $Filter => $FilterValue)
+ if (GetValue($Filter, $Categories[$ID], FALSE) == $FilterValue)
+ unset($Categories[$ID]);
+ }
+
+ // No categories that are otherwise filtered out
+ elseif (is_array($RestrictIDs) && !in_array($ID, $RestrictIDs))
+ unset($Categories[$ID]);
+ }
+
+ Gdn::UserModel()->JoinUsers($Categories, array('LastUserID'));
+
+ $Result = new Gdn_DataSet($Categories, DATASET_TYPE_ARRAY);
+ $Result->DatasetType(DATASET_TYPE_OBJECT);
+ return $Result;
+ }
+
/**
* Get full data for a single category by its URL slug. Respects permissions.
*
@@ -295,7 +295,7 @@ public function GetWhere($Where = array(), $Offset = 0, $Limit = FALSE) {
if($Perms !== TRUE) {
if (isset($Where['d.CategoryID'])) {
- $Where['d.CategoryID'] = array_intersect((array)$Where['d.CategoryID'], $Perms);
+ $Where['d.CategoryID'] = array_values(array_intersect((array)$Where['d.CategoryID'], $Perms));
} else {
$Where['d.CategoryID'] = $Perms;
}
@@ -1786,10 +1786,8 @@ public function AddView($DiscussionID) {
// Increment. If not success, create key.
$Views = Gdn::Cache()->Increment($CacheKey);
- if ($Views === Gdn_Cache::CACHEOP_FAILURE) {
- $Views = $this->GetWhere(array('DiscussionID' => $DiscussionID))->Value('CountViews', 0);
- Gdn::Cache()->Store($CacheKey, $Views);
- }
+ if ($Views === Gdn_Cache::CACHEOP_FAILURE)
+ Gdn::Cache()->Store($CacheKey, 1);
// Every X views, writeback to Discussions
if (($Views % $WritebackLimit) == 0) {
@@ -57,13 +57,11 @@ public function __construct() {
}
public function GetData() {
+ $this->SetData('Content', FALSE);
$SelectorMethod = 'SelectBy'.ucfirst($this->Selector);
if (method_exists($this, $SelectorMethod)) {
$this->SetData('Content', call_user_func(array($this, $SelectorMethod), $this->Selection));
- return TRUE;
}
-
- $this->SetData('Content', FALSE);
}
/**
@@ -96,7 +94,6 @@ protected function SelectByRole($Parameters) {
// Check cache
$SelectorRoleCacheKey = "modules.promotedcontent.role.{$RoleID}";
$Content = Gdn::Cache()->Get($SelectorRoleCacheKey);
- $Content = FALSE;
if ($Content == Gdn_Cache::CACHEOP_FAILURE) {
@@ -1,30 +1,11 @@
<?php if (!defined('APPLICATION')) exit();
-/*
-Copyright 2008, 2009 Vanilla Forums Inc.
-This file is part of Garden.
-Garden is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
-Garden is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-You should have received a copy of the GNU General Public License along with Garden. If not, see <http://www.gnu.org/licenses/>.
-Contact Vanilla Forums Inc. at support [at] vanillaforums [dot] com
-*/
+
/**
* VanillaHooks Plugin
*
* The class.hooks.php file is essentially a giant plugin container for an app
* that is automatically enabled when the app is.
*
- * @package Vanilla
- */
-
-/**
- * Defines all plugins Vanilla uses.
- *
- * These fire automatically when their respective events are called with
- * $this->FireEvent('EventName') and are passed the object that calls the event by reference.
- * Plugin methods are usually defined by names in the pattern: {Class}_{Event}_Handler.
- * The Render method may be hooked into using {Class}_Render_Before.
- * You may use "Base" as the class when hooking into Dashboard events.
- *
* @link http://vanillaforums.org/docs/PluginQuickStart
* @since 2.0.0
* @package Vanilla
@@ -9,21 +9,25 @@
$Content = $this->Data('Content');
$ContentItems = sizeof($Content);
- if ($this->Group):
- $Content = array_chunk($Content, $this->Group);
- endif;
-
- foreach ($Content as $ContentChunk):
+ if ($Content):
+
if ($this->Group):
- echo '<div class="PromotedGroup">';
- foreach ($ContentChunk as $ContentItem):
- WritePromotedContent($ContentItem, $this);
- endforeach;
- echo '</div>';
- else:
- WritePromotedContent($ContentChunk, $this);
+ $Content = array_chunk($Content, $this->Group);
endif;
- endforeach;
+
+ foreach ($Content as $ContentChunk):
+ if ($this->Group):
+ echo '<div class="PromotedGroup">';
+ foreach ($ContentChunk as $ContentItem):
+ WritePromotedContent($ContentItem, $this);
+ endforeach;
+ echo '</div>';
+ else:
+ WritePromotedContent($ContentChunk, $this);
+ endif;
+ endforeach;
+
+ endif;
?>
</div>
</div>
@@ -95,6 +95,8 @@ public static function Link($Path, $Text = FALSE, $Format = NULL, $Options = arr
$Class = GetValue('class', $Options, '');
$WithDomain = GetValue('WithDomain', $Options);
$Target = GetValue('Target', $Options, '');
+ if ($Target == 'current')
+ $Target = trim(Url('', TRUE), '/ ');
if (is_null($Format))
$Format = '<a href="%url" class="%class">%text</a>';
@@ -42,6 +42,7 @@ function smarty_function_link($Params, &$Smarty) {
if (isset($Params['withdomain'])) $Options['WithDomain'] = $Params['withdomain'];
if (isset($Params['class'])) $Options['class'] = $Params['class'];
if (isset($Params['tk'])) $Options['TK'] = $Params['tk'];
+ if (isset($Params['target'])) $Options['Target'] = $Params['target'];
$Result = Gdn_Theme::Link($Path, $Text, $Format, $Options);

0 comments on commit 483834d

Please sign in to comment.