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

Help with new tab page add-on

edited May 2006 in Vanilla 1.0 Help
I've been playing around with adding a new tab with user-definable text as an extension, originally designed for a static FAQ & Help tab modelled on the "About Settings" tab. I have got it working okay, but ran into a few problems on the way, which may or may not have implications for a few vanilla settings

I'll say it right away, I'm a designer-with-some-technical-understanding rather than a programmer and the result is more an "assemblage" cobbled-together out of approaches others have taken before me in other threads on the forum.

The extension entitled "extensions/HelpPage/default.php" looks like this:
<?php /* Extension Name: New Text Tab Extension Url: Description: Allows one to add a new text tab with a custom name and URL. Version: 0.5 Author: JR Author Url: */ // include settings from external file include_once($Configuration['EXTENSIONS_PATH'] . 'HelpPage/settings.php'); // 1. DEFINE VARIABLES AND PROPERTIES SPECIFIC TO THIS PAGE // Set context for tab to appear depending on whether user is logged in or not if ($NewTab_GuestRead == 1) { $NewTabSettings['NewTab_GuestRead'] = $Context->Session->UserID >= 0;} else { $NewTabSettings['NewTab_GuestRead'] = $Context->Session->User->RoleID;} // Tab position seem to be 10, 20, 30... therefore to insert a tab in second place it should be (2*10)-5 = 15 $NewTabSettings['NewTab_Position'] = ($NewTab_Position * 10) - 5; $NewTabSettings['NewTab_PageTitle'] = $Context->GetDefinition('NewTab_PageTitle'); $NewTabSettings['NewTab_PageURL'] = $Context->GetDefinition('NewTab_PageURL'); // Read out URLvar and see if it matches NewTab_PageURL as means of testing if we are on the right page $RightPage = (($Context->SelfUrl) && (ForceIncomingString('page', '') == strtolower($NewTabSettings['NewTab_PageURL']))) ? true : false; // Add the new Tab if(in_array($Context->SelfUrl, array('index.php', 'comments.php', 'search.php', 'account.php', 'settings.php', 'categories.php', 'post.php')) && $NewTabSettings['NewTab_GuestRead']) { $Menu->AddTab($NewTabSettings['NewTab_PageTitle'], $NewTabSettings['NewTab_PageTitle'], $Configuration['BASE_URL'] . strtolower($NewTabSettings['NewTab_PageURL']) .'/', '', $NewTabSettings['NewTab_Position'], ''); } // Ensure the user is allowed to view this page $Context->Session->Check($Context); if ($RightPage) { class NewPage extends Control { var $Data; function NewPage(&$Context) { $this->Name = 'NewPage'; $this->Control($Context); } function Render() { $this->CallDelegate('PreRender'); include('my_newtab.php'); $this->CallDelegate('PostRender'); } } // Define properties of the page controls that are specific to this page // Body id="NewTab_PageURL" because less likely to include spaces, be invalid etc. $Head->BodyId = $NewTabSettings['NewTab_PageURL']; $Menu->CurrentTab = $NewTabSettings['NewTab_PageTitle']; $Panel->CssClass = 'DiscussionPanel'; $Panel->BodyCssClass = 'Discussions'; // 2. BUILD PAGE CONTROLS $NewPage = $Context->ObjectFactory->CreateControl($Context, 'NewPage'); // 3. ADD CONTROLS TO THE PAGE $Page->AddRenderControl($Head, $Configuration['CONTROL_POSITION_HEAD']); $Page->AddRenderControl($Menu, $Configuration['CONTROL_POSITION_MENU']); $Page->AddRenderControl($Panel, $Configuration['CONTROL_POSITION_PANEL']); // This is the new one $Page->AddRenderControl($NewPage, $Configuration['CONTROL_POSITION_BODY_ITEM']); $Page->AddRenderControl($Foot, $Configuration['CONTROL_POSITION_FOOT']); $Page->AddRenderControl($PageEnd, $Configuration['CONTROL_POSITION_PAGE_END']); // 4. FIRE PAGE EVENTS $Page->FireEvents(); exit(); } ?>

Vanilla tells me the post is too long, so the rest continues in the comment below:

Comments

  • Options
    edited May 2006
    The code for the page it includes I separated out into another file "my_newtab.php" so one doesn't have to fiddle with the plug-in if you want to change the output.
    <?php // Basic HTML frame modelled on Vanilla's "About Settings" page // Change to suit your requirements. Strings and contained HTML // are in settings.php in this extension. echo '<div id="Form" class="Settings Help"> <fieldset> <legend>'.$this->Context->GetDefinition('NewTab_Header').'</legend> <form method="post" action=""> '.$this->Context->GetDefinition('NewTab_Content').' </form> </fieldset> </div>'; ?>

    Finally, the settings for the Tab Name, Url and Title and the HTML-strings for the content itself are also in a separate file called "settings.php":
    <?php // Set to 1 if guests should be able to see the tab, 0 if only once logged in $NewTab_GuestRead = 1; // Set position where the tab is to be inserted $NewTab_Position = 6; // Set Page Title for Tab $Context->Dictionary['NewTab_PageTitle'] = 'FAQ & Help'; // Set URL Title for Tab $Context->Dictionary['NewTab_PageURL'] = 'help'; // Set Strings for Page Title and Page Content $Context->Dictionary['NewTab_Header'] = 'Frequenty Asked Questions'; $Context->Dictionary['NewTab_Content'] = ' <p class="Description">This is a description up front:</p> <dl> <dt>FAQ question?</dt> <dd>Answer to question.</dd> <dt>FAQ question?</dt> <dd>Answer to question.</dd> </dl>'; ?>

    Things I'm not sure if I did them the 'right way':
    1. How best to give the tab an URL of its own when it doesn't refer to a particular php file. I borrowed from ithcy's example in his first chat plug-in and had it append ?page=tab-url to the URL
    2. How to make the content only appear in the context of this new page (as it has no newtab.php to test against). Again, I borrowed from ithcy's method of testing for the existence of the appended ?page= on the URL. Without it, the content takes over all tabs.
    3. without exit() at the end of the extension I get a whole load of errors.
    4. I'm sure there's a more elegant syntax for the if guest bit at the top.
    5. Is $Configuration['BASE_URL'] still valid. I still have it from my manual install but I vaguely remember reading something about it being removed. If so, what should I use instead?
    6. This only makes one new tab. I guess one could rename the extension and install it several times in different extension folders to make new tabs, but I'm sure there's a better way to make several tabs out of one extension.
    Problems:
    I wanted to use friendly-URLs so I added the following to the end of .htaccess (I have the friendly_urls on in the settings)
    #Help RewriteRule ^help/$ index.php?page=help [QSA,L]
    This works great, but it breaks the sign-in and sign-out link when these are clicked from the help page because it calls /help/people.php and can't find it. I finally got around it by changing the sign-in and sign-out URLs in the configuration. I added the following to "conf/settings.php":
    $Configuration['SIGNIN_URL'] = $Configuration['BASE_URL'] . 'people.php'; $Configuration['SIGNOUT_URL'] = $Configuration['BASE_URL'] . 'people.php?PostBackAction=SignOutNow';
    Maybe I've made an unnecessary problem here in the way I went about things, or maybe these settings are better made standard in appg/settings.php?

    Any improvements very welcome.
  • Options
    No takers on this one? Everything okay? Too poor to correct ;-)

    Already came across one problem. The URL should be output differently depending upon whether clean-urls are set or not. My solution was to change this section in the middle:
    // Add the new Tab if(in_array($Context->SelfUrl, array('index.php', 'comments.php', 'search.php', 'account.php', 'settings.php', 'categories.php', 'post.php')) && $NewTabSettings['NewTab_GuestRead']) { // Test to see if clean urls are in use and produce link string accordingly if ($Configuration['URL_BUILDING_METHOD'] == 'mod_rewrite') { $Menu->AddTab($NewTabSettings['NewTab_PageTitle'], $NewTabSettings['NewTab_PageTitle'], $Configuration['BASE_URL'] . strtolower($NewTabSettings['NewTab_PageURL']) .'/', '', $NewTabSettings['NewTab_Position'], ''); } else { $Menu->AddTab($NewTabSettings['NewTab_PageTitle'], $NewTabSettings['NewTab_PageTitle'], $Configuration['BASE_URL'] . 'index.php?page=' . strtolower($NewTabSettings['NewTab_PageURL']), '', $NewTabSettings['NewTab_Position'], ''); } }
  • Options
    I can't get this extension to even show up in the extensions page...something I'm doing wrong? I'm using Vanilla 1.0 prerelease and I've copid these scripts exactly as they appear into a directory called NewTab and placed that in my extensions folder, but it doesn't show up on the list

    I'm really wanting to add about 3 or 4 tabs at the top so something like this is just up my alley

    SkyBlueshoes
  • Options
    In the example, the folder is called HelpPage. If you give it another name, you'll have to change the path in the include_once at the top of default.php.

    Also, if you make several copies of the extension with different names for several pages, you'll also need to adjust the config settings for each page so that they have a unique name or they will overlap and conflict, i.e. several instance all defining NewTab_ ...

    It's probably doable, just not very elegant. I'm sure SirNot will come up with a better overall solution with his PageManager.
  • Options
    blizeHblizeH ✭✭
    I know this isn't really very helpful, but if it's any consolation the ability to create new pages using the vanilla template/theme that are accessible via tabs at the top of the page (next to discussions, categories, search etc, right?) sounds absolutely fantastic and something I'd definately use.
  • Options
    blizeH, that's what I use it for (in my case an FAQ page) - it uses whatever template is in use. If you mean create new pages automatically from the settings tab, then I think that's what SirNot's plugin did (don't know for sure as I've not used earlier vanilla versions).
  • Options
    Yeah, I tried doing multiple pages with it and the tab order is all out of whack, the tabs disappear and reappear as you move around the site. I think I'll wait to see how good SirNot's plugin is going to work! Hopefully, he'll get a move on, lol ;)


    SkyBlueshoes
This discussion has been closed.