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

extra page plugin question

13

Comments

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    Please post everything from public function Base_Render_Before($Sender) { up to the closing bracket

  • Options
    rbrahmsonrbrahmson "You may say I'm a dreamer / But I'm not the only one" NY ✭✭✭

    @R_J said:
    If it is placed right after that line, there is no place for $Session = Gdn::Session();...

    That's in the original plugin source. Regardless, I do not understand your remark...

  • Options
    R_JR_J Ex-Fanboy Munich Admin
    edited March 2014

    It would be easier to judge what you are doing if you post a complete function. Even if it is the original source, I do not know it by heart ;)

    If the next line after public function Base_Render_Before($Sender) { is $RoleArray = Gdn::UserModel()->GetRoles($Session->UserID)->ResultArray();, you do not have set the variable $Session.
    The function GetRoles() needs a UserID. You can get the UserID from the Session user. In order to get that, you will need to fill the $Session variable: $Session = Gdn::Session();. That code will print you all the user roles:

    public function Base_Render_Before($Sender) {
       $Session = Gdn::Session();
       $RoleArray = Gdn::UserModel()->GetRoles($Session->User->UserID)->ResultArray();
       decho($RoleArray);
    ...
    
  • Options
    R_JR_J Ex-Fanboy Munich Admin

    Edited the above, because now I was forgetting about first getting the User from Session and also tried getting directly the UserID...

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    @rbrahmson said:
    Well, I'm just the victim here;-))) The source of Peregrine's latest version has this:

    <?php if(!defined('APPLICATION')) die();
    
    $PluginInfo['ExtraPage'] = array(
       'Name' => 'ExtraPage',
       'Description' => 'simple plugin to add extra page or 2 extra pages or 3 extrapages - option for modules in  panel. Examples of role-based dispaly and userphoto and user anchor provided',
       'Version' => '3.0',
       'SettingsUrl' => '/dashboard/settings/extrapage',
       'Author' => "Peregrine",
       'MobileFriendly' => TRUE,
    
    );
    
    class ExtraPagePlugin extends Gdn_Plugin {
    
        public function Base_Render_Before($Sender) {
         //  uncomment line below if you only want to show option to logged in users
         //  if (!Gdn::Session()->IsValid())  return;
         //  $Session = Gdn::Session();
     
         // uncomment below if you want to test for a role before adding link. then test for roles in the role array.
         // $RoleArray = Gdn::UserModel()->GetRoles($Session->UserID)->ResultArray();
         // $Roles = ConsolidateArrayValuesByKey($RoleArray, 'Name');
         
    

    So all I did was to follow the commented advice to un-comment these lines...The rest is history where a mortal proved that gods can err;-)
    Still, the mortal has no clue how to fix it...Appreciate any help.

    Sorry! Now I've got it! In fact if that code is from the plugin @shadowdare will have to work over it. Please change $Session->UserID to $Session->User->UserID and try again

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    @R_J said:
    Sorry! Now I've got it! In fact if that code is from the plugin shadowdare will have to work over it.

    ... or @peregrine. I guess it's time for weekend...

  • Options
    hgtonighthgtonight ∞ · New Moderator

    @R_J said:
    Please change $Session->UserID to $Session->User->UserID and try again

    The session actually stores the user ID as a top level member, so this change shouldn't be required. If it still doesn't work, I would decho the $Session and make sure it is populated. (although you shouldn't be able to see a decho if the session isn't valid)

    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
    R_JR_J Ex-Fanboy Munich Admin

    I didn't knew that (and I think it is a waste of whateveriswastedwhenyoustufftoomanyinfointothesession because if Session->User is already stored, adding Session->UserID is redundant)

    And it was at least a good sounding explanation why that simple piece of code shouldn't work :D

  • Options
    peregrineperegrine MVP
    edited March 2014
    • what is it you want to do @rbrahmson.
    • I actually sleep and eat and a few other things :) as part of my circadian rhythm.
    • At those times I am not on the forum

    just tell me simply. How many extra links or different links do you want. I personally don't think it is a good idea to have a zillion potential links and pages based on roles. It is much better in my opinion to have a few links in menu for all roles and display the same view for all roles and spit out with what is necessary for that role.

    here is a simple way to test - your forum is not live anyway you said.

    public function Base_Render_Before($Sender) {
    $Session = Gdn::Session();
    if (!$Session->IsValid()) return;  // ignore non-logged in users.
    // you must be logged in to show the array.......
     $RoleArray = Gdn::UserModel()->GetRoles($Session->UserID)->ResultArray();
     $Roles = ConsolidateArrayValuesByKey($RoleArray, 'Name');
    // this should spit out roles in the $Role array. 
    var_dump($Roles);
     die();
    

    @rbrahmson said: Well, I'm just the victim here;-))) The source of Peregrine's latest version has this:

    you won't be a victim if you ...

    please go through the tutorial for basic constructs - go thru the entire www3schools.com for php.
    spend a day - you will be happier.

    http://www.w3schools.com/php/php_arrays.asp

    also look at var_dump() and die() at php.net. the above is just for testing to help you understand.

    the comment ...

    // uncomment below if you want to test for a role before adding link. then test for roles in the role array.

    made the assumption one knows a bit about what is going on. The code has no bugs, I am aware of. the comments are not totally explanatory though and require some understanding and you may introduce your own bugs

    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
    peregrineperegrine MVP
    edited March 2014

    @rbrahmson
    your basic problem is this.

    if you use this. The basic idea if you are going to be using $Session multiple times...
    it is easier to get it first with
    $Session = Gdn::Session();

    In that way you don't have to keep on repeating $ Gdn::Session() everywhere and just use $Session. Since there are multiple things you can uncomment and comment. you have to understand a few basics and the comments are just pointers to aide you on the way. They are not absolutes. Told you you might learn something.

    if you are logged in - it will work.

        $Session = Gdn::Session();
        $RoleArray = Gdn::UserModel()->GetRoles($Session->UserID)->ResultArray();
       var_dump($RoleArray);
    

    I'd give myself a yak-shaver badge for updating plugin if I could.

    http://vanillaforums.org/badge/yak-shaver

    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
    rbrahmsonrbrahmson "You may say I'm a dreamer / But I'm not the only one" NY ✭✭✭

    @peregrine: sometimes my wiered humor is not understood, hope I wasn't offending you. Indeed as a newbie to this I think that it is a given it is unlikely that the bug is in your code rather than my playing with it.

    You and other seers pointed me to lots of reading materials and it is overwhelming, especially when I don't really plan, have time, or able to be a real programmer. So what I do is a little playing, absorbing what I can with my little time and experience. That said, you were absolutely correct in asking "what is it that you want". The what precedes the how, what they call "Business Requirements".

    Background: we will have multiple categories only visible to members in roles that allow them to see these categories. Usually members will have access to a single category (through their role), but sometimes a user will have access to more than one (rarely more than two) by being assigned more than one role. We will be using categories as forums managed under one installation for ease of administration. Some of the categories will have "Extra pages", and when a category has an extra page, we only want to show it to a user that has access to that category.

    Therefore:
    (1) We're not concerned about flooding the menu bar with menu options.
    (2) If the extra page does not exist we don't want to add it to the menu (as I said earlier, not every category has an extra page).
    (3) We want to easily manage the menu text (what the user see and click on) as we add categories and roles. That is what we call the "translation" between the category name and the menu text.

    Note: The roles and categories are highly correlated - that is why the scanning of roles made some sense. I think it would be more elegant if instead I scanned the categories and checked if the user has a viewing permission to the category and only then add the page.

    Current status of my mods to the plugin: I made the changes you suggested to the plugin, created the for loop and getting the role correctly (namely the "bug" disappeared). The next step is to do the translation, verify that the url file exists and then add the menu adding in the for loop logic ($Sender->Menu->AddLink($Extramenu,$Extramenu,$Extraurl);)

    I thought that I could do the translation with the "T(" function and translate English to English to manage and keep the relationship between the roles and menu text in the en-CA file in Locale. That didn't work... I think Vanilla is smart enough not to translate a language into itself...So I need aother solution.

    Now everyone knows how far (and little) I managed to get, and what's missing. Any advice will be appreciated.
    Note: I'll be traveling the next few days with limited web access so I'll probably have more time to address this after my travel.

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    You can create a dropdown so it does not populate the menu too much. You can also predetermine who can see the link by giving the link permissions.

    You can also give the page permissions so if someone who is not allowed tries to access the link, they are redirected back to the discussions.

    No, vanilla does not know about the words you translate. It does not matter if you are changing english words with other english words. The Translate aspect of T is to replace a word with something else. Not to know what language it is in and then refuse to do something. Locales are simply replacement words for existing words.

  • Options
    peregrineperegrine MVP
    edited March 2014

    . 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.

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    You can use a plugin like categories2menu or categories dropdown to add the script for the drop down then change your links like this:

    $this->Menu->AddLink('Home', T('Home'), '/');

    to get links into the drop down you use the name of the parent link as the target

    $this->Menu->AddLink('Home', T('Mobile View'), 'profile/mobile');
    $this->Menu->AddLink('Home', T('Activity'), 'activity');
    $this->Menu->AddLink('Home', T('otherlink'), 'link etc');
    

    to give the links special permissions like this, the example below link only shows if logged in

    $this->Menu->AddLink('New Discussion',T('New Discussion'),'/post/discussion', array('Garden.SignIn.Allow'), array(), array('target' => '_blank'));

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    You can also use this function to make sure a certain link only appear at a certain time under certain circumstances. The one bellow will only show if the device is mobile.

    public function MenuModule_BeforeToString_Handler($Sender) {
    
      // The event is fired by all the menus when they are rendered. Using HtmlId, 
      // we can distinguish which menu fired it and alter it accordingly
    
      if(($Sender->HtmlId == 'Menu') && IsMobile()) {
        $Sender->AddLink('MobileHome', Img('/plugins/MobileHome/mhicon.png', array('alt' => T('MobileHome'))), '/mobilehome',  array('class' => 'MobileHome'));
      }
    }
    
  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    If anyone deserves the Yak shaver Badge it is peregrine. No one shaves yaks like you do and I mean no one !!!!

  • Options
    rbrahmsonrbrahmson "You may say I'm a dreamer / But I'm not the only one" NY ✭✭✭

    @peregrine: No, I didn't ask someone to write it for me, just few pointers when we all know that a few lines of code would do the trick.
    No, what I specified did not "complicate it with a million possible page links".
    I've had less aggressive experience in this forum. I am a bit dismayed by your feedback.
    I am going to disengage this discussion.

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    get a grip peregrine has only been helping you and all of us too...

    just few pointers when we all know that a few lines of code would do the trick

    Sometimes you need to understand the code to be able to use it . It is not as simple as give me the code to copy and paste. If you don't understand where it goes or what it does. It takes time to understand it. and no one can do it for you.

    peregrine remade this plugin in an attempt to help you with your needs. There is no need to be rude. his feedback is always useful to me.

    good luck with your endeavors, by the way kicking a gift horse in the mouth is dismaying.

  • Options
    rbrahmsonrbrahmson "You may say I'm a dreamer / But I'm not the only one" NY ✭✭✭

    @vrijvlinder said:
    You can use a plugin like categories2menu or categories dropdown to add the script for the drop down then change your links like this:

    $this->Menu->AddLink('Home', T('Home'), '/');

    to get links into the drop down you use the name of the parent link as the target

    $this->Menu->AddLink('Home', T('Mobile View'), 'profile/mobile');
    $this->Menu->AddLink('Home', T('Activity'), 'activity');
    $this->Menu->AddLink('Home', T('otherlink'), 'link etc');
    

    to give the links special permissions like this, the example below link only shows if logged in

    $this->Menu->AddLink('New Discussion',T('New Discussion'),'/post/discussion', array('Garden.SignIn.Allow'), array(), array('target' => '_blank'));

    Thanks @vrijvlinder. Will look at these.

  • Options
    rbrahmsonrbrahmson "You may say I'm a dreamer / But I'm not the only one" NY ✭✭✭

    I'm afraid I see it the other way around -- I felt that his feedback was rude - that if I don't do it his way, then I should take a hike. And I did explain in another post that I asked accounting to set up paypal and promised to donate to him and others in appreciation. Which I plan to do even though I feel dismayed.

    Let us all cool down.

Sign In or Register to comment.