Users running a non-download version of Vanilla (pulled from github), on branch release/2019.016 or master from the last 2 weeks should upgrade to release/2019.017 or latest master for security reasons. Downloaded official open sources releases are not affected.
Please upgrade here. These earlier versions are no longer being updated and have security issues.

How to remove a category from the category sidebar?

I am using NillaBlog to set up a category (Site News) as a blog. I also added this category as my homepage. Because it's now the index/homepage of the forum I would like to remove its listing from the category box in the sidebar.

I would not really like to use javascript or css for this, I want to do it server-side.

«1

Comments

  • peregrineperegrine MVP
    edited July 2013

    what version of vanilla?

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • ShadowdareShadowdare Moderator
    edited July 2013

    Edit: nevermind.

    Add Pages to Vanilla with the Basic Pages app

  • @peregrine 2.0.18.8 (Sorry about not including that from the get go)

  • ShadowdareShadowdare Moderator
    edited July 2013

    I wasn't able to override the CategoriesModule class and view in Vanilla 2.2 alpha, which I use for my main Vanilla development site. It doesn't look like it has any events to hook into, and I also don't think it fires any magic events for the module. So, I have been testing out some things and came up with a solution that will remove the link to the categories you set in NillaBlog in the Vanilla CategoriesModule.

    • This solution requires PHP 5.4 because it uses new features.
    • Tested with NillaBlog 1.8.1 on Vanilla 2.2 alpha and it should work in 2.0.18.8.
    • This solution looks messy and is hackish in a way because it's modifying a private object property from the $Sender of Base_Render. I am posting this here because it may be useful for other people who are in a situation like this.
    • It is easier to modify the CategoriesModule module file instead of using this, but if you don't want to touch the core files, then you can use the following solution in the plugin. If you don't mind editing the core file, you only need to add the foreach statement below and change the variable to the correct one somewhere in the file.
    • It is much easier and simpler to use JavaScript or CSS to hide the link, because people can still go to the link directly or probably find it somewhere else on your website.

    Add the following to in plugins/NillaBlog/class.nillablog.plugin.php:

       public function Base_Render_Before($Sender) {
          // Remove Categories set in NillaBlog from CategoriesModule
          if(isset($Sender->Assets['Panel']['CategoriesModule'])
                && (count(C('Plugins.NillaBlog.CategoryIDs')) > 0)
                   && (version_compare(PHP_VERSION, '5.4.0') >= 0)) {
             $GetPrivateObject = function &($Object, $Item) {
                $Result = &Closure::bind(function &() use ($Item) {
                      return $this->$Item;
                   }, $Object, $Object)->__invoke();
    
                return $Result;
             };
             
             $CategoriesModuleData = &$GetPrivateObject($Sender->Assets['Panel']['CategoriesModule']->Data, '_Result');
             
             foreach(C('Plugins.NillaBlog.CategoryIDs') as $CategoryID)
                unset($CategoriesModuleData[$CategoryID]);
          }
       }
    

    Add Pages to Vanilla with the Basic Pages app

    peregrineUnderDogvrijvlindersiliconsara
  • Thank you so much for this; it works on my xampp localhost setup but not on my dreamhost account. I get Parse error: syntax error, unexpected T_FUNCTION in /home/pnet/predaphiles/test/plugins/NillaBlog/class.nillablog.plugin.php on line 169

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    unexpected T_FUNCTION might be a missing " } " somewhere?

  • @vrijvlinder Not that I can see, I checked the closing brackets and they all appear to be closed properly. It's on this line:

    $GetPrivateObject = function &($Object, $Item) {
    
  • Ahh no wonder, dreamhost uses php version 5.2

    vrijvlinderUnderDog
  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    Guess it is not much of a dream eh? lol

    UnderDog
  • Ahh, well, in dreamhost's defense I just found out I can switch to 5.4 in the control panel; it's just not there on default. I should have it running in ten minutes. :D

    vrijvlinderUnderDog
  • edited July 2013

    Huh, I updated the php version to 5.4, waited 10 minutes and made the code changes. I don't get the T_function error anymore but neither does the category disappear from the module. Should I wait longer? I also cleared my install's cache.

    Ah-ha! You have to move the category to the bottom of the list for the snippet to work.

    vrijvlinderUnderDog
  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    Maybe you can post the entire code or zip the mods for others to use if they want to ?

    UnderDog
  • Here you go, this has the snippet in place: http://pastebin.com/WnKm1iNW

    Just delete what's in /NillaBlog/class.nillablog.plugin.php and replace it with this.

    vrijvlinderUnderDog
  • peregrineperegrine MVP
    edited July 2013

    never mind.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • @peregrine The file I posted surpassed the character limit.

  • ok

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    here I zipped it so it can be here for posterity :)

    class.nillablog.plugin.php with mods

    UnderDog
  • hgtonighthgtonight ∞ · New Moderator

    @Shadowdare said:
    I wasn't able to override the CategoriesModule class and view in Vanilla 2.2 alpha, which I use for my main Vanilla development site. It doesn't look like it has any events to hook into, and I also don't think it fires any magic events for the module. So, I have been testing out some things and came up with a solution that will remove the link to the categories you set in NillaBlog in the Vanilla CategoriesModule.

    Hate to post a me too on an answered thread, but I do this in my blander blog plugin. I just hook into the categories module and unset anything that matches the configuration.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • ShadowdareShadowdare Moderator
    edited July 2013

    @hgtonight: I actually looked at the Blander Blog plugin before I made the post and saw that you used some hooks for the categories module, but for some reason the hooks or creating a new class and view file didn't work for me so I thought it didn't work for modules. I'll look into it.

    Add Pages to Vanilla with the Basic Pages app

  • hgtonighthgtonight ∞ · New Moderator

    I am going to chalk it up to being up too late.

    I overrided the actual categories module class to remove the categories I wanted.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

Sign In or Register to comment.