Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Hiding categories and still keeping posting privelages

edited January 2008 in Vanilla 1.0 Help
I was wondering if it is possible to hide certain categories without disallowing people to post in them. Since I am creating a forum for comments on certain anime reviews I don't want people to find the discussion pages by going on the forum part. I tried looking for an extension or an option with vanilla but i only found one that disallows certain groups to participate, which sounds to me like they wouldn't be able to post in that category.

Comments

  • So you want to prevent a certain category from being listed on the 'all discussions' page for a certain role?
  • i want that for the all discussions page and the category page, but still allow all roles to be able to post replies in them.
  • edited November 2006
    Sorta like using the 'block category' option but with out the option?

    ...

    I've got a hunch this might work for the discussions page (its untested):
    function Category_HideFromDiscussions(&$SqlBuilder) { $SqlBuilder->AddWhere('c', 'CategoryID', '', '6', '<>', 'and', '', 0, 0); } $Context->AddToDelegate('SqlBuilder', 'PostGetDiscussionBuilder', 'Category_HideFromDiscussions');
    where 6 is the category ID you want to block.

    Unfortunately, there isin't a similar delegate (as of Vanilla 1.0.1) for the category manager, so until then you might have to paste that AddWhere line inside \library\Vanilla\Vanilla.Class.CategoryManager.php
  • actually all i need is the discussions one, since I got rid of the category tab and I am using that discussion overview extension. So this might just do the trick. Where do I put in this code though? I'm not sure which file I need to go into and where in that file.
  • It can go in its own extension... just copy and paste the standard extension comments, change as needed, add the code before the ?> then put it in a folder inside extensions and name it default.php.

    Oh, and make sure that there isn't any white space or extra lines outside the <?php and ?>, this can cause some hard-to-find validation errors.
  • well i couldn't figure out how to get the extension to work, i could make the file but it just wasn't working.
  • edited November 2006
    This code is tested and workes:<?php /* Extension Name: Category Hider Extension Url: http://www.lussumo.com/addons Description: Hides certian categories from the discussion grid Version: 1.0 Author: WallPhone Author Url: http://wallphone.com/ */ // CONFIGURATION: Edit the two array() statements in the code to reflect the category IDs that should be blocked. // The code blocks categories 5 and 6, but if you wanted to instead block categories 1, 3, and 6, then use // array('1', '3', '6') in place of the other two array functions. if ( ('index.php' == $Context->SelfUrl) && !in_array(ForceIncomingString('CategoryID', ''), array('5', '6')) ) { function Category_HideFromDiscussions(&$DiscussionManager) { $SB = &$DiscussionManager->DelegateParameters['SqlBuilder']; foreach ( array('5', '6') as $CurrentBlock ) { $SB->AddWhere('t', 'CategoryID', '', $CurrentBlock, '<>', 'and', '', 0, 0); } } $Context->AddToDelegate('DiscussionManager', 'PostGetDiscussionBuilder', 'Category_HideFromDiscussions'); $Context->AddToDelegate('DiscussionManager', 'PreGetDiscussionCount', 'Category_HideFromDiscussions'); } ?>
    Let me know if you have any other issues.
  • edited December 2006
    I just noticed a wierd bug where the discussion list doesn't page as normal... My guess is that GetDiscussionCount needs to have the category blocked also...

    EDIT: Now fixed above.
  • This is almost fully working now, great job. :) The only thing that isn't working right, is that it still displays the category on the discussions tab, but when you click on it to go into the category it hides all the discussions, but when I go to the review page and click on the link to the discussion it allows me to view it and post to it. ^.^
  • edited November 2006
    Sorry this took so long, but I have edited the above code to now correctly report the number of posts in a category, and it will also NOT hide any posts for the category when you go inside it. Oh, and you can now have multiple categories blocked.

    All that is really left is the control panel for an admin to check/uncheck which categories they wish to hide (instead of forcing them to change those two array() functions)

    I will upload to the add-ons site when that control panel is built in.
  • ok awsome i'll try out the code in a little bit then. I figured out how to block more than one category with the old code, I just pasted the line that had the category number in it, on the next line and changed it to the other category and it worked lol. Thanks for the help, I hope other poeple will find this add-on useful too.
  • I just disabled the use of categories and use the DiscussionTags extension. http://lussumo.com/addons/?PostBackAction=AddOn&AddOnID=226
  • Just what I was looking for.

    I have a category called Archives and I am using this to hide archived discussions from the main discussions list and will hopefully be able to use CategoryRoles to prevent new discussions and comments being added. The purpose is for admins and moderators to move old discussions to the archive, maintaining them for reference only.

    It's the equivalent of locking a category.

    I hope to make this into an extension sometime...called Locked Categories or something.
  • edited January 2008
    If you want to hide the categories from the categories page, this will work:

    if ($Context->SelfUrl == 'categories.php') { function VanillaGroups_HideCategory(&$CategoryManager) { $s = &$CategoryManager->DelegateParameters['SqlBuilder']; $s->AddWhere('t', 'CategoryID', '', {CategoryToBeHidden}, '!='); } $Context->AddToDelegate('CategoryManager', 'PostGetCategoryBuilder', 'HideCategory'); }

    Copy the "AddWhere" line for each category to be hidden, or do another one of those "foreach" conditions Wallphone suggests.
This discussion has been closed.