Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Any to give users their own selection of homepage layout?

13

Comments

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    I can tell you right now what it is ...

    don't close the first php tag and don't open new ones unless it is to echo something

  • Options
    DoyceTDoyceT Model Questioner ✭✭✭

    Okay, I made peregrine's suggested changes to file names and it uploaded.

    http://vanillaforums.org/addon/customhomepage-plugin-0.2

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP
    <?php if (!defined('APPLICATION')) exit(); 
    
    
    $PluginInfo['CustomHomepage'] = array(
       'Name' => 'Custom Homepage',
       'Description' => 'This plugin allows users to set their own choices for which homepage they will see when they connect to the forum.',
       'Version' => '0.2',
       'Author' => "Doyce Testerman - but really peregrine and hgtonight - plus vrijvlinder for the awesome icon.",
       'AuthorEmail' => 'doyce.testerman@gmail.com',
       'AuthorUrl' => 'http://vanillaforums.org/discussion/27138/any-to-give-users-their-own-selection-of-homepage-layout'
    );
    
    
    class CustomHomepagePlugin extends Gdn_Plugin {
    
    public function UserModel_AfterGetSession_Handler($Sender) {
        $Request = Gdn::Request();
       if($Request->Path() == '') {
       $User = $Sender->EventArguments['User'];
    
    // override the default controller route temporarily if it has been set
    
       $Controller = $this->GetUserMeta($User->UserID, 'DefaultController', FALSE, TRUE);
       if($Controller) {
       Gdn::Router()->SetRoute('DefaultController', $Controller, 'Internal', FALSE);
       }
     }
    }
    
    public function Gdn_Dispatcher_AfterControllerCreate_Handler($Sender) {
       $User = Gdn::Session()->User;
       $Controller = $Sender->EventArguments['Controller'];
    
    // override the default layout temporarily if applicable
    
       switch($Controller->ControllerName) {
       case 'discussionscontroller':
       $DiscussionsLayout = $this->GetUserMeta($User->UserID, 'DiscussionsLayout', C('Vanilla.Discussions.Layout', NULL), TRUE);
       SaveToConfig('Vanilla.Discussions.Layout', $DiscussionsLayout, array('Save' => FALSE));
       break;
       case 'categoriescontroller':
       $CategoriesLayout = $this->GetUserMeta($User->UserID, 'CategoriesLayout', C('Vanilla.Categories.Layout', NULL), TRUE);
       SaveToConfig('Vanilla.Categories.Layout', $CategoriesLayout, array('Save' => FALSE));
       break;
       }
    }
    
    public function ProfileController_EditMyAccountAfter_Handler($Sender) {
       $User = $Sender->User;
    
    // Load their current settings
    
       $Controller = $this->GetUserMeta($User->UserID, 'DefaultController', FALSE, TRUE);
       $DiscussionsLayout = $this->GetUserMeta($User->UserID, 'DiscussionsLayout', FALSE, TRUE);
       $CategoriesLayout = $this->GetUserMeta($User->UserID, 'CategoriesLayout', FALSE, TRUE);
    
    // Save the settings to the form
    
       $Sender->Form->SetValue('DefaultController', $Controller);
       $Sender->Form->SetValue('DiscussionsLayout', $DiscussionsLayout);
       $Sender->Form->SetValue('CategoriesLayout', $CategoriesLayout);
       $ControllerOptions = array(
       'discussions' => 'Discussion List',
       'categories' => 'Category List'
       );
       $LayoutOptions = array(
       'modern' => T('Modern non-table-based layout'),
       'table' => T('Classic table layout used by traditional forums')
       );
       echo '<li class="Homepage">';
       echo $Sender->Form->Label('Homepage View', 'DefaultController');
       echo $Sender->Form->DropDown('DefaultController', $ControllerOptions, array('IncludeNull' => TRUE));
       echo $Sender->Form->Label('Discussions View', 'DiscussionsLayout');
       echo $Sender->Form->DropDown('DiscussionsLayout', $LayoutOptions, array('IncludeNull' => TRUE));
       $LayoutOptions['mixed'] = T('All categories listed with a selection of 5 recent discussions under each');
       echo $Sender->Form->Label('Categories View', 'CategoriesLayout');
       echo $Sender->Form->DropDown('CategoriesLayout', $LayoutOptions, array('IncludeNull' => TRUE));
       echo '</li>';
    }
    
    public function UserModel_AfterSave_Handler($Sender) {
       $FormValues = $Sender->EventArguments['FormPostValues'];
       $UserID = val('UserID', $FormValues, 0);
    
    // Require valid user ID
    
       if(!is_numeric($UserID) || $UserID <= 0) {
       return;
       }
       $DefaultController = val('DefaultController', $FormValues, FALSE);
       if($DefaultController) {
       $this->SetUserMeta($UserID, 'DefaultController', $DefaultController);
       }
       $DiscussionsLayout = val('DiscussionsLayout', $FormValues, FALSE);
       if($DiscussionsLayout) {
       $this->SetUserMeta($UserID, 'DiscussionsLayout', $DiscussionsLayout);
       }
       $CategoriesLayout = val('CategoriesLayout', $FormValues, FALSE);
       if($CategoriesLayout) {
       $this->SetUserMeta($UserID, 'CategoriesLayout', $CategoriesLayout);
       }
       }
       public function OnDisable() {
       return TRUE;
       }
    }
    
  • Options
    DoyceTDoyceT Model Questioner ✭✭✭

    Also incorporated vrij's cleanup of the php tags. Icons and screenshot added.

  • Options

    why are you including this

    public function OnDisable() {
    return TRUE;
    }

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

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    I told him to do so ... was it wrong? that makes sure it disables no?

  • Options
    peregrineperegrine MVP
    edited June 2014

    .

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

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    I tested other plugins which were reported to not disable, they did not have it all the other aspects were ok. Name etc. I added it and it disabled. May be a coincidence . Maybe it is unnecessary but I have seen it in several plugins which made me think it was useful function to have.

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    Maybe this one is more useful

    public function OnDisable() { $this->_EmptyCache(); }

    or this one to get rid of the settings too

    public function OnDisable() {
          RemoveFromConfig('Plugins.CustomHomepage.Enabled');
       }
    

    Mostly this appears in theme hooks look at bittersweet theme hooks

    public function OnDisable() {
          return TRUE;
       }
    
  • Options
    peregrineperegrine MVP
    edited June 2014

    @vrijvlinder

    remove it and test if you can disable the theme :).

    in a plugin it doesn't matter either way probably.

        public function OnDisable() {
        return TRUE;
        }
    

    vs.

    nothing at all.

    other than there is less code.

    @DoyceT

    only other improvement (nitpicks) for next update time is to remove the extra <?php

    e.g.

    change
    
    <?php if (!defined('APPLICATION')) exit(); ?>        
     <?php
    $PluginInfo['CustomHomepage'] = array(
    
    
                    to
    
     <?php if (!defined('APPLICATION')) exit(); 
      $PluginInfo['CustomHomepage'] = array(
    

    and to format it so it is indented properly. you can use netbeans for formatting (a free ide).

    nice job. probably not worth the trouble to change unless you add more features.

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

  • Options
    DoyceTDoyceT Model Questioner ✭✭✭

    In the interest of getting everything discussed so far included while it's all still fresh, I've removed the extra <?php as well as the code at the end designed to help it disable cleanly (it disables successfully without it).

    Newest version uploaded to the addon page as v 0.2.2.

  • Options
    peregrineperegrine MVP
    edited June 2014

    another feature should anyone feel up to it that would be cool (I think)

    is to have an additional dropdown

    Text Size Change

    default
    large text
    small text 
    

    that changes font size in discussion titles and the body of discussion (at the least).

    could probably incorporate selection and add a smalltext.css, largetext.css) if the user selects either one.
    if default is selected do nothing.

    would help older people with ailing eyes and vision impaired people.

    something generic that would work with at least bittersweet theme and default themes that increases font by a percentage (perhaps instead of a number) and decreases fon-size (for people with good eyes who want to see more titles of discussions on the discussion page (without scrolling excessivley).

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

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited June 2014

    just make a style sheet with this in it

        html,body,div, span, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, ins, kbd, q,  samp, small, strike, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td{
        font-size:120%!important;
        }
     or just 
    
    body{
    font-size:120%!important;
    }
    
  • Options
    peregrineperegrine MVP
    edited June 2014

    @vrijvlinder

    did you try it? - does it look ok on your themes. when you add it to the bottom of your css.

    which is essentially what an additional css file would do.

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

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited June 2014

    did you try it? - does it look ok on your themes. when you add it to the bottom of your css.

    I tried it here on this forum by adding it to the body css using web inspector. It makes everything 120% larger and looks great !!

    The one other example with all the elements I use with VFonts.

  • Options

    I might play. probably need to do some importants if adding to css. changing on web inspector doesn't follow inheritnace of pre-existing css because you've changed the pre-existing css :).

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

  • Options
    hgtonighthgtonight ∞ · New Moderator

    You only need to define Setup and Disable functions when you are implementing the plugin interface. Since you are extending the plugin class (which already defines the required interface functions), you don't need to override them.

    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.

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    yes using !important is important to make this work for real . It works with the VFonts plugin.

  • Options
    peregrineperegrine MVP
    edited June 2014

    just to clarify for me and others @hgtonight

    Is this what you mean

    class ABC implements Gdn_IPlugin {
     needs  Setup and Disable functions
    
    vs.
    
    
    class DEF  extends Gdn_Plugin {
       doesn't  need Setup and Disable functions
    

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

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    I guess theme hooks Implement IPlugin and that is why they contain OnDisable True

    You can also see this in old plugins which implement instead of extend so it is not a matter of theme hooks or plugin but how it is used ?

    Interesting..

Sign In or Register to comment.